0

Why the result is 16?

I'm learning slowly this JS language, but I cannot understand why this one: ------------------------------------------------------------------ //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); ------------------------------------------------------------------ gives as result 16. I've tried to understand by taking out some of the sections, but still I don't get it. I appreciate all help! Have an amazing day :)

12th Apr 2020, 9:36 AM
M. Cristian
2 odpowiedzi
+ 2
Hello M. Cristian sum = 0 i = 4 sum += i is shortcut for sum = sum + i sum = 0 + 4 = 4 sum = 4 i = 5 sum += 5 = 9 sum = 9 i = 6 -> continue sum = 9 i = 7 sum += 7 = 16 i = 8 -> end loop output: 16 about break and continue: https://www.sololearn.com/learn/JavaScript/1143/?ref=app
12th Apr 2020, 9:47 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Output:4+5+7=16
12th Apr 2020, 9:51 AM
Alexander Lebedev
Alexander Lebedev - avatar