Break and Continue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Break and Continue

Could someone please explain? I did the last question of "Break and Cotinue" The question was "What is the output of this code? var sum=0 for(i=4; i<8; i++){ if(i==6){ continue; } sum+=i; } document.write(sum); Output;16

26th Feb 2017, 7:23 PM
Sara
Sara - avatar
1 Answer
+ 6
if i == 6 it will ignore the rest of the code for that index, so it won't sum +=6, for the rest of the i in that for statement it will. So you have 0+4=4 4+5=9 "skip" i=6 and continue with the rest, so 9+7=16
26th Feb 2017, 8:28 PM
C.E.
C.E. - avatar