+ 1
JS question
Hello guys, can someone explain this code, please? Thanks a lot. var b = 0; for(var i = 0; i <= 2; i++) { for (var j = 0; j <=3; j++) { b++; } } alert(b); Output is 12.
2 Antworten
+ 2
The inner loop runs 4 times, the outer loop 3 times.
So the inner loop will be executed 3 times.
This means, b is increased 3*4 times.
+ 1
Loop in loop => first 4 steps in the inner loop increment b => 4, then 3 times in the outer loop repeating the inner loop => 3 * 4 => 12.