Anatomy of a `for` Loop
Loops help us repeat code. Click on each highlighted part of this `for` loop to understand its role.
Identify all parts!
Predict the Output
Read the code below carefully. What exactly will it print? Type the *full output* in the box, including any new lines.
Explore `range()`
The `range(n)` function is key for fixed loops. It generates numbers starting from 0 up to (but NOT including) `n`. Enter a number and see what sequence `range()` creates!
Spot the Correct Loop Pattern
Not all loops are written correctly! Click on the code blocks below that show a *syntactically correct* `for i in range(n):` loop structure (check keywords, colon, indentation). Then click "Check Selection".
Loop Mini Missions!
Time to write some loops! Complete these coding tasks using the simulator. Remember the `for`, `in`, `range()`, `:`, and indentation!
Mission 1: Repeat Three Times
Write a Python loop that prints the word "Hello" exactly 3 times, each on a new line.
Mission 2: Number Sequence
Write a loop that prints the numbers 0, 1, 2, and 3, each on a new line. (Hint: What number should go inside `range()`?)
Mission 3: Print on Same Line
Write a loop that prints "* " (star followed by a space) 5 times, all on the **same line**. (Hint: Use `print("* ", end="")` inside the loop.)
Module 12 Practice Complete!
Excellent work looping through these exercises! You're getting the hang of fixed iteration.
Ready for more complex loops? Try the Advanced Practice for Module 12!