I’m pretty sure this code loops infinitely?..
The outer loop will never reach the loop termination condition… Should the check condition be “i > 1” instead?
I’m pretty sure this code loops infinitely?..
The outer loop will never reach the loop termination condition… Should the check condition be “i > 1” instead?
The loop does terminate. As you can see that when i = 1, the loop after execution would make i = 1/2 which is ‘0’. Hence, the loop terminates perfectly fine.
If it was double i instead it of int i then it would never terminate, but since it is int i so values for which i should be < 1 would be automatically gets converted to 0.
Hope this helps.