0
Conditionals and Loops Break and Continue
So I'm on the question that the code is: var sum=0; for(i=4; i<8; i++) { if (i == 6) { continue; } sum += i; } document.write(sum); And so if "i" starts at 4 and the loop continues as long as i is less than 8 and for as long as that is not the case "i" is incremented, then how come the result doesn't look like... "457"? And how come the answer is 16? When the sum is 0 and how come i is 8?
2 Réponses
+ 1
Each time the for loop run, i is added to sum ( this is sum+=i , you could have write it sum=sum+i)
So first loop i=4 --> sum=4
2nd loop i=5 --> sum =4+5=9
3rd loop i=6 --> continue
4th loop i=7 --> sum=9+7=16
+ 2
It's an int and not a string.