I\'ve seen both of these two for statements:
for(i=0;i<10;i++)
for(i=0;i!=10;i++)
I know they all stop when i reaches 10
, bu
Both will work in most situations.
If for some reason the body of code executed in the loop changes i
to something greater than 10
, the first version will stop looping, but the second will execute forever.
The best practice is to use != only with iterators (C++) and < otherwise. Never ever use == or != with floats/doubles. The following loop is an infinite loop:
for (double i = 0.0; i != 1.0; i += 0.1)
printf("yes, I'm an infinite loop ;)");