while...loop with continue statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

while...loop with continue statement

Error, any solution,please??? public class Program { public static void main(String[] args) { int x = 1; while (x< 10) { if(x == 5) { continue; } System.out.println(x); x += 1; } } } _Output: 1 2 3 4 Time limit exceeded

3rd May 2017, 11:12 PM
Long Doan
Long Doan - avatar
3 Answers
+ 6
If you want to use continue then increment x before the continue statement. if(x == 5) { x++; continue; }
4th May 2017, 4:18 AM
Rrestoring faith
Rrestoring faith - avatar
+ 3
Once x reaches 5, "continue" will forever prevent "x += 1" from being executed again. Eventually, the program is terminated for running too long. Did you, perhaps, mean to use "break" instead of "continue"?
3rd May 2017, 11:20 PM
Igor B
Igor B - avatar
0
No, I just wanna test the while..loop with the 'continue' statement instead of testing for...loop with it. anyway thanks for helping
3rd May 2017, 11:50 PM
Long Doan
Long Doan - avatar