How the iterations has done in the give for loop

for i in range (2)
for j in range (2)
print(i,j)
#explain indetail of regarding occuring inside loop iterations

1 Like

@syamprasaderraballi
Hello,
The explanation is that if you run first (for loop) it will run for i = 0, and the second (for loop) will run for i =0 and i= 1 (since range go till n-1).
And in the next iteration of first (for loop) i.e. i = 1 the second (for loop) again run for i = 0 and i =1.
This is the called as nested loop (means loop inside loop).

Hope this will help you to understand.
Thanks

1 Like