The code below outputs 2 and that's why I find it hard to read. Can someone be nice enough to explain plizzz? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

The code below outputs 2 and that's why I find it hard to read. Can someone be nice enough to explain plizzz?

var y=0; for(var x=0; x<3; x++) { if(x==2) { x=5; continue; } y++; } document.write(y);

28th Jun 2019, 8:13 PM
eMBee
eMBee - avatar
5 Answers
+ 5
y will be incremented twice. When x is 0, and when x is 1. When x equals 2, x becomes 5, and then it continues, so y won't be incremented. x isn't smaller than 3, so the loop stops
28th Jun 2019, 8:22 PM
Airree
Airree - avatar
+ 4
Oh, Airree thanks for the short and precise explanation, it helped
28th Jun 2019, 8:26 PM
eMBee
eMBee - avatar
+ 1
Airee is right
28th Jun 2019, 8:35 PM
stephen haokip
stephen haokip - avatar
0
Ismonix Boom Thank you for your contribution, but on sololearn you shouldn't really swear :/
2nd Jul 2019, 11:35 AM
Airree
Airree - avatar
- 1
fack you
2nd Jul 2019, 11:34 AM
Ismonix Boom
Ismonix Boom - avatar