Module 13: Advanced Practice

Exploring nested loops, `range`, `enumerate`, and control flow.

Nested Loop Simulator

Nested loops run loops inside other loops. See how the inner loop completes fully for each outer loop iteration. Modify the `print` statement to see different outputs.

Output will appear here...

`range()` Explorer

The `range()` function generates sequences of numbers, often used in `for` loops. Experiment with different start, stop, and step values.

Sequence will appear here...
Equivalent Code:
for i in range(5): print(i)

`enumerate()` Demo

Need both the index and the item while looping? `enumerate()` is your friend! It pairs each item with its index (starting from 0 by default).

Output will appear here...

Loop Control: `break` & `continue`

You can change a loop's flow using break (exit loop entirely) and continue (skip to next iteration). Observe their effect.

Output will appear here...

Advanced Loop Challenges

Combine your knowledge! Solve these challenges using nested loops, `range`, `enumerate`, or control flow as needed.

Challenge 1: Simple Grid

Use nested loops with `range` to print a 2x3 grid of coordinates like `(0,0) (0,1) (0,2)` on the first line and `(1,0) (1,1) (1,2)` on the second line. Use `print(f"({row},{col})", end=" ")` inside the inner loop and `print()` after the inner loop.

Challenge 2: Enumerate Evens

Given `items = ["A", "B", "C", "D"]`, use `enumerate` to print only the items at even indices (0, 2, etc.) in the format: `Index 0: A`, `Index 2: C`.

Challenge 3: Find First Multiple

Use `range(1, 11)` (numbers 1 to 10) and `break` to find and print the first number that is divisible by 3. Print only that number (which should be 3).

Advanced Practice Complete!

Fantastic! You've explored more powerful looping techniques. Keep practicing these concepts!
Check the Video Lesson for explanations or return to the Course Menu.