+ 1
class MyClass { public static void main(String[ ] args) { int a=0; int even = 0; for(even = 0;even <= 100;++even
why the output is exceeding 100 in above code?
1 Respuesta
0
in a for loop, the first statement is called once,at the beginning. even is then set to 0.
The second statement, the condition is always tester BEFORE the code in the loop is testet.
The last statement is always called AFTER the code in the loop is executed. So, as you use <= , 100 is the last number its true.
But then it still gets incremented once.
Then even is 101 , so bigger than 100 and the loop stops