+ 1

Why did "continue" skip more than one value?

I wrote a do while loop with "continue" in it for practice, to mele it skip one value. Here it is:. (i will jump the class and method strings). int m=3; do { if (m==5) { continue } System.out.println(m); m++; } while (m<7); As the output I obtain only a 3 and a 4, and not also the 6 I expected. Can someone explain me why?

1st Jan 2017, 5:13 PM
Vlaufoo
Vlaufoo - avatar
3 Antworten
+ 3
being m=5...it is become infinite loop..if m=5,true,continue,if m=5,true continue
1st Jan 2017, 5:22 PM
Somnath Ghosh
Somnath Ghosh - avatar
+ 2
You created an endless loop cause your m++ in line 7 will not be executed for m==5 because your continue is executed before.
1st Jan 2017, 5:19 PM
Andreas K
Andreas K - avatar
0
Thank you I got it now.😀
1st Jan 2017, 5:24 PM
Vlaufoo
Vlaufoo - avatar