0

Why this JS code executing number 16?

var sum=0; for (i=4; i<8; i++) { if (i==6) { continue; } sum +=i; } document.write(sum);

18th Jan 2019, 9:17 PM
Dev Anand
Dev Anand - avatar
2 Respostas
+ 11
First Value of i=4 If condition not satisfied Sum=4 Next Value of i=5 Condition not satisfied Sum = (4+5)=9 Next Value of i=6 Condition satisfied Continue Next Value of i=7 Condition not satisfied Sum =(9+7)=16 Next i=8 not less than 8 So loop condition not satisfied it will terminate Hence sum =16
18th Jan 2019, 9:37 PM
AKS
AKS - avatar
+ 1
Thank you very much, got it
18th Jan 2019, 10:02 PM
Dev Anand
Dev Anand - avatar