Ms. Whitby's Classroom logo Ms. Whitby's Classroom

Iteration & Accumulation — Lesson 1: Repeat an instruction

New skill: For loops and ranges
Previously learned: Unit 05 — conditional execution

Why this matters

A loop makes Python repeat an instruction without copying the same line over and over. range() produces a sequence of integer values.

Study this example

for checkpoint in range(1, 5):
    print(checkpoint)

The displayed values are 1, 2, 3, 4. The final argument of range() is exclusive. The body must be indented.

Before moving on, predict the result of the program or function. Then run it and compare.

Check your understanding

What values are produced by range(2, 6)?

Common mistake

range(1, 5) does not include 5. Use range(1, 6) when you need to include 5.

Practice

Use a loop with range() to display the integers 1, 2, 3, 4 on separate lines. Do not use four individual print statements.

Expected console output

1
2
3
4

Open the Python starter

Hint 1 `range()` controls how many loop iterations occur.
Hint 2 The ending argument is not included.
Hint 3 Place a single print call inside the loop.

Reflection

Explain why your solution works and describe one boundary case you tried.