+ 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);
3 Respostas
+ 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
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.