+ 1

var sum=0;for(I=4;I<8;I++){if (I==6){continue;}sum+=I;} document.write(sum); the output is 16.... can anybody explain the process of getting 16...

12th Oct 2016, 11:52 AM
Shabana.A
Shabana.A - avatar
2 Answers
+ 3
In your loop, I takes the values 4, 5, 6 and 7 successively, and they are added to sum except when I is 6 (continue skips the current loop). At the end of the execution, sum is thus equal to 4+5+7 = 16.
12th Oct 2016, 1:01 PM
Zen
Zen - avatar
+ 2
in loop for i=4 sum=sum+i=4 as sum =0, new sum=4, now for i=5 sum=sum+i=4+5=9, as sum was5, for i=6 if loop condition is true, continue will move execution to start of for loop, now i=7 so sum=sum+i=9+7, so sum=16, for i=8, condition is not true,so end of loop
13th Oct 2016, 1:43 PM
Abhinav Dhiman
Abhinav Dhiman - avatar