0

Can we use continue in the block of while loop?

Why this code not working: let I = 7; while (I) { if (I==3) continue; console.log(i—); }

25th Dec 2019, 10:38 AM
Andrey
Andrey - avatar
8 ответов
+ 3
Like this let i = 7; while(i > 0) { if(i == 3) { continue; } console.log(i--); }
25th Dec 2019, 11:34 AM
Nico Ruder
Nico Ruder - avatar
+ 2
After the i is a line and not 2 minuses (--) and another reason can be that you use capital I and lowercase i
25th Dec 2019, 11:29 AM
Nico Ruder
Nico Ruder - avatar
+ 1
Also I think it isn't neccessary, but you should put the "continue" statement into { }.
25th Dec 2019, 11:33 AM
Jan Štěch
Jan Štěch - avatar
+ 1
Yep, it should work now. 👍
25th Dec 2019, 11:35 AM
Jan Štěch
Jan Štěch - avatar
+ 1
issue is continue will go back to the while loop and ‘i’ will never get to decrement, should be let i = 7; while(i==3) { i—; continue; } console.log(i—); } ✌🏻
25th Dec 2019, 12:13 PM
Andrey
Andrey - avatar
0
Hm, I was fast with confirming this is working, runinig in WebStorm to Chrome and still getting Page uresponsive error
25th Dec 2019, 11:54 AM
Andrey
Andrey - avatar
0
You should use for cycle instead. for (let i = 7; i > 0; i--) { if (i == 3){continue;} console.log(i); }
25th Dec 2019, 12:16 PM
Jan Štěch
Jan Štěch - avatar
0
agree, I just confused why it not working with while solution is need to use decrement two times
25th Dec 2019, 12:17 PM
Andrey
Andrey - avatar