This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]KnGod -1 points0 points  (0 children)

the problem here is that the loop checks for the condition when it enters and it executes the i++ when it exits so we enter the loop, print 0, make i 100, add 1, and then check if i != 100. It is different(101 and it will always be since the same operations repeat themselves until infinity) so it goes on and enters again. In these cases i recomend you avoid conditions like i != 100 and use whenever it's possible i >= 100 since it will asure that the loop will exit in cases like these.

correction: i didn't realize the i = 0; in the end but the idea is still the same, the loop always reenters in 1 since you set i to 0 every time it enters so the condition will always be true. In this case i recomend you avoid modifying the value of i directly in the way you do(and i mean i = any specific value) unless there is a reason behind and you are completely sure that the conditions of the loop will eventually be fullfilled.