+ 5
Why is the answer 16 for this question?
what is the output of this code? var sum=0; for(i=4; i<8; i++) { if (i==6) { contuine; } sum +=i; } document.write(sum);
8 Answers
+ 38
i=4
then i is minor to 8
i is not equal to 6
then sum=4, becasue 0=0+4 -> sum=4
i=5
then i is minor to 8
i is not equal to 6
then sum=9, becasue 4=4+5 -> sum=9
i=6
then i is minor to 8
i is equal to 6
then jum to end the for
i=7
then i is minor to 8
i is not equal to 6
then sum=9, becasue 9=9+7 -> sum=16
i=8
then i is not minor to 8, but is equal the the for is end, and the output is 16 for sum
+ 3
i thought it was 24, but that was because I was so used to the lessons using <= that i didn't read it carefully enough to see it was actually < only. my goof.
+ 3
the top comment explains it well but if you really want to simplify it, the answer is basically what is 4 + 5 + 7
+ 2
thank you, I finally understand it. đđđ
+ 2
because this has nothing to do with toast and this forum seems to use html encoding to prevent that arbitrary Javascript most likely due to security. Good job to the forum coders!
+ 2
1st iteration 4, 2nd (4+5)=9, and 3rd( 9+7)=16..
0
nice explenation just to add "think in a loop the sum isn't closed if the loop is < then 8 so for exemple remove the if i==6 continue and the awnser is 22 sum=0+4+5+6+7 and the loop stops. because 4+1+1+1+1= not less then 8 its 8 and your command is <8.
0
Finally understand this now, thank you very much for the explanation, forgot that the addition wasn't outside the loop