+ 4
what is answer for this loop and why?
var i = 1; for (k=1; k<10; k++) { i += k; }
5 Answers
+ 1
var i = 1;
for
(k=1; k<10
;
k++)
{
i += k;
}
that would work đđ
0
For what,
you can try in code playground (4th button, with {} icon)
For why,
1 + 1 + 2 + 3 +.... + 9
0
d1spache thanks I just could not understand why the answer was 46
;)
0
output would be: 2 4 7 11 16 22 29 37 46
k=1 i=1
i = i + k;
i = 1 + 1; = 2
k = 2; i = 2;
i = i + k;
i = 2 + 2; = 4
k = 3; i = 4;
i = i + k;
i = 4 + 3; = 7
k = 4; i = 7;
i = i + k;
i = 7 + 4; = 11
and so on