[Info-vax] decrementing & for loops in C

Bob Eager rde42 at spamcop.net
Fri Jan 9 16:18:34 EST 2009


On Fri, 9 Jan 2009 20:48:38 UTC, JF Mezei 
<jfmezei.spamnot at vaxination.ca> wrote:

> Bill Gunshannon wrote:
> 
> > What possible difference could it make wether you had the x++ in the
> > parentheses part of the for loop or just on a line all by itself?  It
> > is still just x++ and should generate exactly the same code.
> > 
> > for (x = 0; i; x++) something;
> > 
> >  x = 0; while ( i ){ x++; something; }
> 
> The alignment of the stars relative to the loudness of the neighbour's
> dog ark may be more conducive to my using "for" loops instead of "while"
> loops on that day ?
> 
> Ane exentric customer demanding that I never use "while" loops in the
> programs I write for them ?
> 
> Or, the program origially uses the for loop in a conventional way. But
> over time, the condition is changed and becomes too complex to fit
> between the semi-colons in the "for" statement, so you just put a
> variable there and put the complex condition in the code and leave that
> block as a "for" loop.

It seems slightly dangerous to use a variable, because some later 
modification to the program may result in that variable being zero - 
which means the loop is never executed.

If I want the condition to be always true, I just omit it...

  for(x = 0; ; x++) something;

since an empty for() condition is defined to be always true.

-- 
Bob Eager




More information about the Info-vax mailing list