Community resourceWorksheet

J277 2.2.1 Count-controlled iteration

Part 5 of 7 · J277 2.2.1-2.2.2 · Programming fundamentals

Count-controlled iteration, used when the number of repetitions is known before the loop starts.

Students will:

  • explain when a count-controlled loop is the right choice
  • use range() with one, two and three arguments
  • accumulate a running total inside a loop
  • predict how many times a loop body runs
  • generate a sequence from a stated requirement

Inside: 7 explanation cells, 3 runnable Python tasks, 3 multiple-choice questions, 1 fill-in-the-blanks cell and 2 written answers. 16 marks, about 45 minutes.

Series: J277 2.2.1-2.2.2 · Programming fundamentals, part 5 of 7.

Shared by Coding PathwayVerified teacher

  • 16 cells
  • About 45 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026
  • Updated 9 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Count-controlled iteration

Iteration repeats instructions. Count-controlled iteration is used when the required number of repetitions is known or can be calculated before the loop starts. In Python, this is normally written with for and range().

Understanding range()

  • range(5) produces 0, 1, 2, 3, 4.
  • range(1, 6) produces 1, 2, 3, 4, 5.
  • The stop value is not included.
Values produced by Python range 1 to 6 Python range 1 comma 6 produces 1, 2, 3, 4 and 5. The stop value 6 is excluded. range(1, 6) 12 34 56 values included stop: excluded

The loop variable takes one value from the range on each repetition. An accumulator such as total keeps a running result and must usually be initialised before the loop.

OCR Exam Reference Language writes a count-controlled loop differently:

for count = 1 to 5
    print(count)
next count

Here, both 1 and 5 are included. This differs from Python's excluded range() stop value. You may write Python in an exam, but you must be able to read OCR's notation in the question.

Following a count-controlled flowchart

This flowchart expresses the same idea as for count = 1 to 5: initialise the counter, test whether it is still within the required range, perform the repeated action, increase the counter and return to the decision.

Flowchart that outputs the values 1 to 5 Start, set count to 1, test whether count is less than or equal to 5, output count when true, add 1 to count and return to the test. Follow the false branch to End. Start count = 1 count ≤ 5? decision True Output count count = count + 1 False End Rectangle: process Diamond: decision Parallelogram: output Arrow: order

Trace from Start and follow the arrows. The output occurs before the counter is increased. When count becomes 6, the decision is False and repetition stops.

Multiple choice1 mark

Trace the count-controlled flowchart. How many times is Output count reached?

  • A4
  • B5
  • C6
  • DIt repeats forever
Multiple choice1 mark

Which Python loop processes the same values as OCR Exam Reference Language for count = 1 to 5 ... next count?

  • Afor count in range(1, 5):
  • Bfor count in range(0, 5):
  • Cfor count in range(1, 6):
  • Dwhile count == 5:

Worked example: looping and accumulating

Before running the example, list the five values taken by day and predict the final total. Notice that the indented print runs on every repetition, while the final print runs once after the loop.

Worked example
total = 0
for day in range(1, 6):
    steps = day * 1000
    total = total + steps
    print(day, steps)
print("Total:", total)
Fill in the blanks3 marks
A loop that repeats a known number of times is label 1 iteration. In range(2, 7), the first value is label 2 and the final value is label 3.
  • condition-controlled
  • count-controlled
  • 1
  • 2
  • 6
  • 7

Supported practice: accumulate a total

Use a count-controlled loop to add the integers from 1 to 5 inclusive. total = 0 is genuine initialisation here: the accumulator needs a starting value before the loop repeatedly adds to it.

Use a range that includes 1, 2, 3, 4 and 5. The final value of total should be 15.

Coding task3 marks
# Use a for loop to total the numbers from 1 to 5 inclusive.
total = 0
# Write the loop here.
Multiple choice1 mark

Which loop displays the integers 1, 2, 3 and 4?

  • Afor n in range(4): print(n)
  • Bfor n in range(1, 4): print(n)
  • Cfor n in range(5, 1): print(n)
  • Dfor n in range(1, 5): print(n)

Independent practice: generate a times table

Build the first twelve values in the 7 times table. Use a for loop with a suitable range(), multiply each loop value by 7, and append each product to results.

results = [] creates an empty Python list. The statement results.append(product) adds one new value to its end. You will study lists in more detail later; here they allow the checks to inspect every value generated by the loop.

The completed list should begin with 7, end with 84 and contain exactly twelve values.

Coding task3 marks
# Create the 7 times table from 1 × 7 to 12 × 7.
results = []
# Append each product to results inside a for loop.
Written answer2 marks

Explain why range(1, 10) does not process the value 10, and give the corrected range if values 1 to 10 inclusive are required.

State the rule for the stop value before giving the correction.

Students type their answer here.

Written answer2 marks

A program must ask for seven daily temperatures and calculate their total. Explain why a count-controlled loop is suitable.

Link the loop type to what is known before repetition starts.

Students type their answer here.

Review

Use count-controlled iteration when the number of repetitions is known or can be calculated before the loop starts. In Python, remember that the stop value in range() is excluded and initialise accumulators before the loop rather than resetting them inside it.