Quote:
You would only get it printed out 499 times. Count starts at 1 and before you do anything with it you are incrementing it to 2 so you loose 1 line of print.
|
Not true, its <= so it will do 500 times, starting loops at 1 is often the sign of a pascal programmer or such switching to C, the ending value will be 501, not 500. so from 2 to 501
int i=500;
while(i--) {
.....
}
simple, uses a faster test which is generally implemented as a single instruction, the whole loop can be done in one instruction on a pc (ignoring the inital load), though some optimizing compilers will pick up on that the for loop and fix it.