0
for loops
please help: why do I get different outputs from this code: 1. int i; for(i = 0;i<100;i++); System.out.println(i); 2. int i; for(i = 0;i<100;i++){ System.out.println(i) ; } please help, how does the insertion of semicolon and curled brackets affect the output..?
3 Answers
0
1 : 100
2: 0 to 99
0
in first case there is no loop body so, only i gets incremented , in the end i is 100 it checks and condition doesn't holds, but the value for i is still 100
in second case there is loop body inside {} braces, so till the condition holds it prints 0 till 99 , but not 100 as before entering the loop body condition is checked , and 100 is not< 99. so end of loop
0
bro... this is helpful.. thanks a lot