GCSE · Computer Science · Edexcel · Spec 1CP2
Count-controlled repetition
Need to print a line of stars 50 times? Please don't paste it 50 times. Write two lines and let a for loop do the counting for you.
Computer Science · Iteration
Watch count skip along
range(2, 11, 2) means: start at 2, stop at 11, go up in steps of 2. Press Next to run the loop one pass at a time and watch what count holds.
Before you press Next: how many times will this loop run — and will 11 ever be printed?
1 for count in range(2, 11, 2):2 print(count)3 print("Finished!")
| Pass | count |
|---|---|
| — | — |
Output
Step 1: Nothing has printed yet. First, range sets up the sequence the loop will walk along: 2, 4, 6, 8, 10. It's fixed before the first pass, so the loop already knows it will run 5 times. 11 isn't in the sequence. It's only where the counting stops.
Step through the trace — every value is the lesson’s, not run by the page.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A for loop knows how many times it will run before it starts. It runs once for each value range gives it, then stops by itself.
What you need to know
- Iteration is repeating a sequence of instructions inside a loop.
- If a count value decides how many repeats you get, that's count-controlled iteration.
- Python does it with a for loop: for every value in a sequence, run the indented block once.
- range is a built-in function that makes that sequence of numbers for the loop.
- Give range one number and it's the stop point, with counting starting from 0.
Have a goYour mate is certain range(3) gives 1, 2, 3: "that's just how counting works!" What does it really give?
0, 1, 2
With one number, range starts at 0 and stops before 3. Your mate started at 1 and kept the stop number, two slips in one go.
- Two numbers mean start and stop. Three mean start, stop and step, the gap between values.
- That stop number never turns up in the sequence. It only marks where counting stops.
Have a goWhat is the very last value range(4, 9) gives you?
8
9 is the stop point, so range stops just before it. Saying 9 treats the stop number as the last value.
- Each pass, the count variable grabs the next value. Values run out? The loop ends by itself.
- How many repeats can come from a variable, like num_users, so nobody copies and pastes lines.
Have a goA game asks how many lives you want and stores the answer in lives. Fill the gap: for count in ______:
range(lives)
range(lives) gives exactly lives values, starting at 0. A fixed number like range(3) ignores whatever the player typed.
The big picture
Iteration means repeating instructions in a loop, and when a count decides how many repeats there are, it's count-controlled. In Python that's a for loop: for every value in a sequence, it runs the indented block once. range generates the sequence. One number is the stop point (counting from 0), two are start and stop, and three are start, stop and step. The stop number is never included. On each pass the count variable holds the next value, and when the values run out the loop ends by itself. The number of passes can come from a variable, such as num_users.
Key points
Worked example
Problem
A running app should print Lap 1, Lap 2, Lap 3, Lap 4 and Lap 5. A student writes: for lap in range(1, 5): print("Lap", lap) What does it actually print, and how do you fix it?
⚠ Watch out
Reading the stop number as the last value. range(2, 11, 2) ends on 10, not 11, because the stop point is never part of the sequence.
Memory hook
Start, stop, step, and stop means stop BEFORE.
Check yourself
Without running it, how many times does for count in range(3, 9, 2): run, and what does print(count) output on each pass?
Flashcards
(13)What is iteration?
What makes iteration count-controlled?
Which Python loop is used for count-controlled iteration?
What does range do?
In range(start, stop, step), what does each number do?
What does range(5) generate?
Why isn't the stop number in the sequence?
What is the count variable?
When does a for loop end?
How many times does for count in range(3, 8): run?
How do you make a loop repeat once for every user?
Why use a loop instead of copying and pasting the same line?
Which range gives 10, 20, 30?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 28 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.