+ 1
Ask about JS nested for loop
Can you tell me why the "outer for loop" didn't loop even when "i=0" is written inside the "for()" (result count=3) but it looped when "j=0" is written inside the "inner for loop" (result count =9) in the following code? https://code.sololearn.com/WifKPaeY77K5/?ref=app
3 Antworten
+ 1
the problem is with j variable..
u have initialized j=0 out of the loop..
so for i=0 run j values are 0,1,2
that's fine.
now for second run i=1, the value of j is not reinitialised to 0 since the j=0 is out of the loop... and it finds that the value of j is 3 and terminates the loop..
+ 1
Man, i didn't realize that.. Thanks for the explanation 👍
0
np ;)