0
Can you run this program and explain me why get that kind of result?
class MyClass { public static void main(String[] args) { int a = 10; int b = 1; int i = 0; while (b <= a || i < 10){ System.out.println(b); b++; if(b == 5) b = 1; i++; } } }
1 Respuesta
+ 3
It is infinite loop, because of your condition
Look,
b=1
a=10
b<=a is true,
b printed, (1 to 5 repeatedly)
b++ when b becomes 5, if statement get executed and so i++ but b is set to 1 again..
Even i<10 becomes false but b values repeated from 1 to 5 again and again and b<=a is always true.. So infinite loop...
Edit :
what is your expected output?