+ 3

Why doesn't run

var x=0; while(x<=10){ if(x==5){continue } document.write(x+"<br>">); x++; }

12th Mar 2020, 5:56 AM
Ãm Sabbir
Ãm Sabbir - avatar
5 ответов
+ 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
17th Mar 2020, 1:58 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 7
Remove > after "<br>" and Check again var x = 0; while (x <= 10) { if(x == 5) { continue; } document.write(x + "<br>"); x++; }
12th Mar 2020, 6:01 AM
A͢J
A͢J - avatar
+ 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(){}...
17th Mar 2020, 2:50 AM
EmmanueLZ.
EmmanueLZ. - avatar
0
var x=0; while(x<=10){ if(x==5){continue} document.write(x); x++; } is it?
12th Mar 2020, 6:05 AM
Ãm Sabbir
Ãm Sabbir - avatar
0
Ãm Sabbir , no I think he asked you to insert the > in between the double quotes.actually, your ending > is outside ...
12th Mar 2020, 4:18 PM
EmmanueLZ.
EmmanueLZ. - avatar