for(;;) { int i=0; if(i==1){System.out.println(i); break;} ++i;} Will this code run for infinite times? If yes then how? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

for(;;) { int i=0; if(i==1){System.out.println(i); break;} ++i;} Will this code run for infinite times? If yes then how?

This is regarding for loop. I want to know how iteration occurs in this case

13th Aug 2017, 7:11 AM
Paul Gaikwad
Paul Gaikwad - avatar
1 Answer
0
it will run infine amount of times cause in the loop you declare 'i' and assifn 0 to it. later you check if it is equal 1 but it is not. next you say "i want i to be 1 now". and then you go back and override 'i with a number of 0
13th Aug 2017, 8:05 AM
Paul