+ 1
Continue statement not working?
https://code.sololearn.com/c9Fr099ZR6u9 I expected the code above to run from 5 to 100 while skipping 25 and then print "Done" when the loop is finished. But the output is 5 to 25. Why is that?
3 Respuestas
+ 5
I agree with Simon Sauter and the solution is:
x+=5;
if(x==25) continue;
+ 3
Two issues:
1. "25" is printed because the output statement comes directly after the increment statement. So when x=20 you add 5 so x=25 and then it is immediately printed and only then in the next iteration the if condition is fulfilled.
2. Your code prints no numbers after that because when x=25 you continue without incrementing. So x remains 25.
+ 1
That would solve both issues.