Year 10 (ages 14–15, Grade 9 in the US) · Computing · GCSE programming · Lesson 4
Count-controlled loops: for and range
Iteration with for loops: using range() with one, two and three arguments, looping over strings, running totals, and nested loops.
Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

8-minute video lesson
Teaching, worked examples and 20 practice questions solved step by step.
Watch free for a monthWhat your child will learn
- Explain count-controlled iteration
- Use range() with start, stop and step
- Keep a running total in a loop
- Trace nested loops
The method
- for repeats a set number of times.
- range(stop), range(start, stop), range(start, stop, step).
- The stop value is NOT included.
- Running total: set to 0 before the loop, add inside.
Key words: iteration, for loop, range, running total, nested loop.
Worked examples
Worked examples from the lesson, with every step.
Question 1
What does this output? c:for i in range(1, 4): c: print(i * 10)
- Step 1: 1, 2, 3 (stops before 4)
- Step 2: 10, 20, 30
Answer: 10, 20, 30 on separate lines
Question 2
List the values from range(5, 20, 5).
- Step 1: 5, then add 5
- Step 2: Stop before 20
Answer: 5, 10, 15
Question 3
What is the final value of total? c:total = 0 c:for x in range(4): c: total = total + x
- Step 1: 0, 1, 2, 3
- Step 2: 0 + 1 + 2 + 3 = 6
Answer: 6