Count-controlled loops in Python

About this lesson: Count-controlled loops in Python

In short

for i in range(start, stop, step) repeats a fixed number of times. The loop stops before it reaches the stop value. Change the three numbers and run it.

Count-controlled loops in Python

What you'll explore

for and range: Start, stop, step
for i in range(start, stop, step) repeats a fixed number of times. The loop stops before it reaches the stop value.
Using a loop: Five turns, one block of code
A game gives each player a set number of turns. Instead of writing the same lines again and again, a loop repeats them. Change the number of turns.
Test the boundaries: First and last pass
We want the numbers 1 to 5. Try three loops and check the first and the last number printed. Which one is right?
Check yourself: Count the passes
for i in range(2, 8): print(i)

Also in this lesson

  • Common mix-ups
  • Loop patterns
  • Times table

Words to know

for loop
A loop that repeats a set number of times.
range
A Python function that makes a sequence of numbers.
count-controlled
Repeating a known number of times.
indentation
Spaces at the start of a line that show structure.
boundary
The first or last value of a range.

Sources

  • BBC Bitesize KS3 Computer Science
  • Raspberry Pi Foundation, Computing curriculum resources

An interactive lesson with a live experiment: move the sliders, press the buttons and answer quick questions. 4 short steps and a 6-question quiz. Part of the Family plan. Written and checked by Shalo Lab. Last updated 11 November 2026.

← Calling a routine · Data types →

All lessons in Term 1 · Computing · Age 13