Tell me why the nested loop for each value of the variable i is executed nine more times?
for (var i = 1; i < 10; i++) { for (var j = 1; j < 10; j++) { document.write(j); } document.write(i + "<br>"); }
Tell me why the nested loop for each value of the variable i is executed nine more times?
for (var i = 1; i < 10; i++) { for (var j = 1; j < 10; j++) { document.write(j); } document.write(i + "<br>"); }
Because it is a nested loop.
Added from comment.
The code that is inside the loop is executed a specified number of times, in your case, 9 times. Accordingly, the nested loop will also be executed 9 times, and the code inside it will be 9 * 9 total 81 times, logically read the code: stumble upon the first loop, do the first pass, stumble upon yet another loop, pass nine passes through it, then we output i, then we return to the beginning of the cycle for the second pass and so 9 times.
Source: https://ru.stackoverflow.com/questions/101377/
All Articles