[Solved] How does a loop in a loop work with python


The inner loop will perform all of its iterations for each iteration of the outer loop.

This is a case where you can test the behaviour yourself fairly easily, and generally it is faster to try these kinds of things out than to ask the question on here and wait for an answer.

For example, given the following code:

for i in range(3):
    print(i)
    for x in ['a', 'b', 'c']:
        print(f' - {x}')

you get the following output:

0
 - a
 - b
 - c
1
 - a
 - b
 - c
2
 - a
 - b
 - c

1

solved How does a loop in a loop work with python