0

Why this problem print 1234, then infinite loop?

int a = 1; while(a <= 10){ if(a % 5 == 0) continue; else System.out.print(a); a++; }

8th Jun 2020, 5:29 PM
Juan Debenedetti
Juan Debenedetti - avatar
2 Réponses
+ 1
It is because when 'a' becomes 5, continue is executed and it moves back to the while condition and 'a' is never incremented. So the if condition is always true.
8th Jun 2020, 5:41 PM
Avinesh
Avinesh - avatar
0
5 % 5 == 0 continue loop after it variable a never increase
8th Jun 2020, 5:40 PM
zemiak