Is it an infinite loop ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is it an infinite loop ?

for (int i=1; i<=10;) { System.out.print(i); }

19th Oct 2019, 4:24 AM
Prince Gupta
Prince Gupta - avatar
3 Answers
+ 3
Yes. The variable 'i' is not being changed in this loop, so the condition will evaluate to true every single time.
19th Oct 2019, 4:36 AM
Brian R
Brian R - avatar
0
yeah but the increment is not there
19th Oct 2019, 4:58 AM
Prince Gupta
Prince Gupta - avatar
0
Exactly. It doesn't need to be there.
19th Oct 2019, 5:02 AM
Brian R
Brian R - avatar