[Info-vax] decrementing & for loops in C
Bill Gunshannon
billg999 at cs.uofs.edu
Fri Jan 9 12:19:17 EST 2009
In article <00537c3d$0$4668$c3e8da3 at news.astraweb.com>,
JF Mezei <jfmezei.spamnot at vaxination.ca> writes:
> Bill Gunshannon wrote:
>
>> In which case this is not a for-loop condition at all and you should have
>> used something like while.
>
> The advantage of a for (x = 0, i, x++) type of loop is that you don't
> need to be bothered with incrementing x, it is done automatically.
Huh???
>
> I wouldn't be susprised if the above resulted in moreefficient
> incrementing of x compared to having a while loop where you manually
> incremented it.
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; }
Granted, one may actually generate more efficient code than the other,
but that would be totally dependant on the knowledge and abilities of
the compiler writer. If he happens to beter understand a for loop he
may code that one better than a while. But then, another compiler may
have this reversed. And the average user will have no way of knowing
which way is better in any given compiler so it really doesn't matter.
bill
--
Bill Gunshannon | de-moc-ra-cy (di mok' ra see) n. Three wolves
billg999 at cs.scranton.edu | and a sheep voting on what's for dinner.
University of Scranton |
Scranton, Pennsylvania | #include <std.disclaimer.h>
More information about the Info-vax
mailing list