+ 4

What is the output of this code and WHY ?

var sum=0; for(i=4; i<8; i++) { if (i == 6) { continue; } sum += i; } document.write(sum); I DONT UNDERSTAND WHY THE OUTPUT OF THIS CODE IS 16, CAN ANYONE EXPLAIN ME THAT ? THANK YOU SO MUCH !!

10th Apr 2018, 7:48 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
3 Answers
+ 16
for loop will be execute till the range that means it execute till 7 4<8 so sum=4+0=4 5<8 so sum=4+5=9 6 came in if block and continue the loop again with next incremented value 7 7<8 so sum=9+7=16 so output is 16
10th Apr 2018, 7:52 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 12
yeah
10th Apr 2018, 8:25 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 4
thank you, so when there is the CONTINUE statement, the code comes back a the starter loop and goes on.
10th Apr 2018, 7:58 PM
Samuele Sacchetti
Samuele Sacchetti - avatar