Is this an Infinite Loop? (Saw this question in a Java challenge. According to the author, the answer is No). | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is this an Infinite Loop? (Saw this question in a Java challenge. According to the author, the answer is No).

for(int i=0;i>=0;i++){ System.out.print(i); }

13th Oct 2019, 9:45 PM
Ifeoluwa Omole
Ifeoluwa Omole - avatar
3 Answers
+ 4
Its not an infinate loop because once i reaches the max integer value of 2147483647 and it increments once more it will become the lowest integer value which is -2147483648 making the condition false.
13th Oct 2019, 10:15 PM
Odyel
Odyel - avatar
+ 2
Makes sense it would loop around due to the integer type size limit, but don't beat yourself up Ifeoluwa Omole , it's a tricky question 🤓
14th Oct 2019, 12:56 AM
will
will - avatar
+ 1
thanks for the answers guys.. didn't think that the program would start again from the lowest int value after reaching the max int value, thereby making the condition false
14th Oct 2019, 3:12 PM
Ifeoluwa Omole
Ifeoluwa Omole - avatar