On Fri, 26 Feb 2010, Isaac Marino Bavaresco wrote: > On 27/2/2010 00:58, sergio masci wrote: > > > > On Fri, 26 Feb 2010, Isaac Marino Bavaresco wrote: > > > > > >> Em 26/2/2010 06:11, Alan B. Pearce escreveu: > >> > >>>> The 'for' construct is much more concise, elegant > >>>> and easier to understand. > >>>> > >>>> > >>> ;))) Not according to Chuck Hellebuyuk that wrote "Beginners Guide to > >>> Embedded C Programming" (available through Microchip). He also doesn't like > >>> the ++ and += styles of notation ... > >>> > >>> > >> I could write a book myself, saying what I like and what I don't, in > >> programming style... > >> > > What did Chuck Hellebuyuk say is bad about 'for' constructs? > > > > Personally I think they are good (not so much the 'C' version - too lax) > > but in general. They allow the compiler to better understand the intent of > > the programmer. > > > > Regards > > Sergio Masci > > > > The most important advantage of 'for' in C is that the initialization > and step sequences are clearly visible. > With the 'while', the initialization sequence is not obviously linked to > the block itself, being easier to overlook or forget to copy/move > together, and the step sequence is not separated from the "worker" > statements. I understand your point of view but it goes much deeper than that. By telling the compiler "this is a controlled loop, with this initial value, this terminating condition and this step" the compiler is able to check the construct for special situations that are (or potentially are) errors. The compiler is also better able to generate much more optimised code. consider: int j; int arr[1000]; for (j=200; j<300; j++) { arr[j] = 0; } a decent compiler could optimise this to unsigned char k; int arr[1000]; int *ptr; for (k=100, ptr=arr+200; k!=0; k--, ptr++) { *ptr = 0; } It could also look at something like for (j=200; j<300; k++) { arr[j] = 0; } and flag 'k++' as a probable error Regards Sergio Masci -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist