+ 2

Can anyone explain this. How the answer is 9?

var i,j; var c = 0; for (i=1; i <=3;i++){ for(j=1; j<=2; j++){ c+=j; } } alert(c);

7th Mar 2020, 5:53 AM
Md. Mubarrat Bin Islam
Md. Mubarrat Bin Islam - avatar
3 Respuestas
+ 4
First loop runs 3 time, and the nested one two times. At each iteration, we add 3 to c (j = 1 and j = 2). Because the first loop runs 3 times, it is equal to 3 * 3 = 9
7th Mar 2020, 6:32 AM
Théophile
Théophile - avatar
0
Innermost loop is running 3times due to outermost loop Condition.i.e., Three time innermost loop runs due to outermost loop which makes c value 9.
7th Mar 2020, 6:31 AM
ƬIMΛ
ƬIMΛ - avatar