0

what is the correct answer and explanation to this loop?

var = 1; for(k=1;k<k10;k++)__ i +=k;

30th Mar 2020, 10:08 AM
Rocky Francisco
Rocky Francisco - avatar
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.
30th Mar 2020, 11:09 AM
Denise Roßberg
Denise Roßberg - avatar
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.
30th Mar 2020, 10:21 AM
Ehsan
Ehsan - avatar