Module 3 - Section 1 - Loops

3.1.3 - Nested for loops

Try to predict what the code below will print. Then enter the code and see if you are correct.

# What does this code prints? Why? for i in range(3): print("a") for j in range(3): print("b")

This next block of code is almost identical to the one above. The second for loop has been indented one tab stop so that it is now nested inside of the first for loop. This changes how the code runs significantly. Try it and see.

# What does this code prints? Why? for i in range(3): print("a") for j in range(3): print("b")


Now try to create a program that will output

Nested Loops Example
1
a
a
a
a
2
a
a
a
a
3
a
a
a

Here you can view a solution to the problem.