Concept
Loops Inside Loops (Nested Loops)
A loop inside another loop is a nested loop:
python
for x in range(2):
for y in range(2):
print(f"Coordinate: ({x}, {y})")
# 65. Loops Inside Loops (Nested Loops) A loop inside another loop is a nested loop: ```python for x in range(2): for y in range(2): print(f"Coordinate: ({x}, {y})") ``` Watch out: Iterations multiply ($N \times M$). Nesting loops over two 10,000-item lists runs 100,000,000 turns, turning your computer into an expensive space heater.
Checkpoint
If outer loop runs 10 times and inner loop runs 10 times, how many total times does the inner code execute?
Practice
Write a nested loop where the outer loop runs `for x in [1, 2]:` and inner loop runs `for y in ["A", "B"]:`. Print `f"{x}{y}"`.
01
Tap code blocks below to assemble
Available Blocks