pyoung673 wrote: |
---|
1 doesn't equal 10 |
etc.
Not the correct explanation.
If the
return 0;
statement is moved out of the loop, where it belongs, an infinite loop results.
First i is initialised with the value 1.
Then the expression
i=10
is evaluated to see whether it is true or false. First, the assignment operation is performed, so i is set to the value 10. Then the result, 10, becomes the result of the expression. In a boolean test, zero is considered
false
and any non-zero value is interpreted as
true
.
After the first pass through the loop, i is incremented via the
i++
operation, and the condition is tested again as above, and i is set to 10 again.
Thus the loop is executed over and over again with exactly the same values.