+ 3
Why doesn't run
var x=0; while(x<=10){ if(x==5){continue } document.write(x+"<br>">); x++; }
5 Answers
+ 6
The code runs and gives error too. Let me explain you what the problem is :
Your code :
var x = 0;
while(x <= 10) {
if (x == 5) { continue; }
document.write(x + '<br>');
x++;
}
Here, give full attention, you are increasing the value of 'x' at the end of the loop. So, when you say x == 5, the code continues running which means that whatever after this statement won't run. So the loop will start again. But the value of x is still same (5). So again, the continue statement runs. Again the value is 5, and starts again. It happens because the loop restarts again after the continue statement and nothing after this statement runs. It makes the loop infinite and sololearn console can't give any error for that. Therefore, if you use the increment before the continue statement, the code will run perfectly.
Like this :
var x = 0;
while(x < 10) {
x++;
if (x == 5) { continue; }
document.write(x + '<br>');
}
https://code.sololearn.com/WIxRiZeVa5Rj/?ref=app
+ 7
Remove > after "<br>" and Check again
var x = 0;
while (x <= 10) {
if(x == 5) {
continue;
}
document.write(x + "<br>");
x++;
}
+ 1
Arb Rahim Badsa
Oh, ok, nice your infos, i thought 'continue' was preventing the code between the if(){} to execute not the whole while(){}...
0
var x=0;
while(x<=10){
if(x==5){continue}
document.write(x);
x++;
}
is it?
0
Ăm Sabbir ,
no I think he asked you to insert the > in between the double quotes.actually, your ending > is outside ...