Why the answer is 16? I don’t get it. | Sololearn: Learn to code for FREE!

0

Why the answer is 16? I don’t get it.

I can not understand why the answer is 16, can someone explain please?

4/10/2021 10:35:42 AM

Jen Teller

5 Answers

New Answer

+11

>> i = 4, sum = 0+4 = 4 >> i = 5, sum = 4+5 = 9 >> i = 6, continue (means skip) >> i = 7, sum = 9+7 = 16 >> i = 8, condition is false, break Output: 16 btw, you wrote "vas" instead of "var". 🙂

+4

Thank you very much guys ;)

+3

i=4, sum = 0 + 4 = 4 // loop start i=5, sum = 4 + 5 = 9 skip coz i == 6 // continue i=7, sum = 9 + 7 = 16 answer i = 8, break false // loop end

+2

Continue skips the current iteration, unlike break that exits loop. Gen has explained the working.

+1

vas sum = 0; for (i = 4; i < 8; i++) { if (i == 6) { continue; } sum +=i; } document.write(sum); The output is 16, and I don’t undestand how 😕