0
what is the correct answer and explanation to this loop?
var = 1; for(k=1;k<k10;k++)__ i +=k;
2 Answers
+ 1
Hello Rocky Francisco
Please add the programming language to the tags.
I guess this is js.
var i = 1;
for (k=1;k<10;k++)
i+=k;
console.log(i); //output 46
k = 1, i = 1
i += k -> i = i + k -> i = 1 + 1
k = 2, i = 2 //i += k = 4
k = 3, i = 4 //i += k = 7
k = 4, i = 7
....
k = 9, i = 37 //i += k = 46
k = 10 -> end loop.
0
is it kotlin? may be there is a mistake in your second line
var = 1;
for (k=1;k<10;k++)
i+=k;
run this code now.