+ 3
Could you explain?
var count=0; for(var i=0; i<=6; i++){ if(i==3){ i=5; continue; } count++; } document.write(count); //output is 4 //could you explain how did we get that output?
3 Réponses
+ 4
After 1. iteration: i=1; count = 1
After 2. iteration: i=2; count = 2
After 3. iteration: i=3; count = 3
After 4. iteration: i=6; count = 4
After the i=3 iteration the if clause will be used. So i=5 and after the continue the for loop will increase i to 6. After that the for loop condition isn't true anymore. :)
+ 2
i=0 --> count++
i=1 --> count++
i=2 --> count++
i=3 --> i=5
i=6 --> count++
+ 1
3 was skipped which means counter incremented 4 times