Lazo Lab Sign up

Python Fundamentals / Loops

Lesson 20 of 38

Nested loops

A loop inside a loop runs the inner loop fully for every round of the outer one. Great for grids and tables.

Key points

  • Inner loop runs completely each time
  • 3 outer x 4 inner = 12 runs
  • Watch out for slow code with big nested loops
for row in range(3):
    for col in range(3):
        print("#", end="")
    print()
Watch a video on thisOpens YouTube search results for “Nested loops” in a new tab

Quiz · +10 XP

An outer loop runs 4 times and an inner loop 5 times. How many inner runs in total?

Log in to save progress and earn XP.