Module 12: Advanced Loops

Let's explore more powerful `for` loop techniques like `range` steps and nested structures.

`range()` Variations

`range()` can do more! Explore `range(start, stop)` and `range(start, stop, step)`. Set the values and see the sequence generated.

range(0, 10, 1)
Sequence will appear here...

Nested Loop Prediction

Loops inside loops! This is called nesting. Predict the exact output of this simple nested loop. Pay attention to each line!

for i in range(2): for j in range(3): print("i:", i, "j:", j)

Spot the Correct Loop Logic

Syntax might be right, but does the loop *do* what's needed? Click the code block that achieves the stated goal.

Goal: Print numbers 5, 4, 3 (each on a new line).

Advanced Loop Missions!

Apply your skills! Use `range` variations and loop logic to solve these tasks in the simulator.

Mission 1: Even Numbers

Write a loop to print all even numbers from 0 up to 8 (inclusive), each on a new line. (Hint: Use the `step` in `range()`!)

Mission 2: Accumulator

Calculate the sum of numbers from 0 up to (but not including) 5. Initialize a `total` variable to 0 before the loop, add the loop variable to `total` inside the loop, and print the final `total` *after* the loop finishes.

Mission 3: Simple Pattern

Write a loop that prints the following pattern:
*
**
***
(Hint: Use the loop variable with the `*` string multiplication operator inside `print()`.)

Module 12 Advanced Practice Done!

Fantastic! You've tackled more complex loop patterns and logic. Repetition is key to mastery.
Reinforce your understanding by reviewing the Practice Exercises or watching the Video Lesson.