Skip to content
Menu

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.

Whiteboard video lesson: Count-controlled loops: for and range

8-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What 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

  1. for repeats a set number of times.
  2. range(stop), range(start, stop), range(start, stop, step).
  3. The stop value is NOT included.
  4. 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)

  1. Step 1: 1, 2, 3 (stops before 4)
  2. Step 2: 10, 20, 30

Answer: 10, 20, 30 on separate lines

Question 2

List the values from range(5, 20, 5).

  1. Step 1: 5, then add 5
  2. 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

  1. Step 1: 0, 1, 2, 3
  2. Step 2: 0 + 1 + 2 + 3 = 6

Answer: 6