Community resourceWorksheet
J277 2.1.2 Trace tables: iteration and nesting
Part 3 of 3 · J277 2.1.2 · Tracing and refining algorithms
Trace tables for loops and nested constructs, the Block A checkpoint.
Students will:
- trace a loop across repeated rows
- keep the loop variable, condition, accumulator and output separate
- finish the inner steps before moving to the next outer value
- trace nested constructs without losing your place
- check a traced answer against the program output
Inside: 3 explanation cells, 3 trace tables, 2 multiple-choice questions and 3 written answers. 12 author-set marks plus the trace-table rows, about 45 minutes.
Series: J277 2.1.2 · Tracing and refining algorithms, part 3 of 3.
Shared by Coding PathwayVerified teacher
- 11 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.
Trace tables: iteration and nesting
Loops create repeated trace rows. Keep the loop variable, condition, accumulator and output separate. For nested constructs, finish the relevant inner steps before moving to the next outer-loop value.
In Python, range(start, stop) includes the start value but excludes the stop value. Therefore, range(1, 5) processes 1, 2, 3 and 4. OCR Exam Reference Language may instead show an inclusive loop such as for value = 1 to 4; always follow the notation provided.
How many values are processed by for value in range(1, 5):?
- A5
- B3
- C4
- DThe loop does not run
Worked loop trace
Trace one repetition at a time. For this algorithm:
total = 0
for value = 1 to 2
total = total + value
next value
print(total)
the accumulator changes from 0 to 1, then from 1 to 3. The final output is 3. The next trace uses the same accumulation pattern with more repetitions, so keep using the previous value of total rather than starting again.
Complete the trace table for the running total.
Create one row for each repetition. Update total using its previous value.
Use one row for each pass through the loop. Fill in a box only when that value changes on that row, and leave the rest blank.
total = 0for value = 1 to 4total = total + valuenext valueprint(total)
| Row | total | value | Output |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 |
State the sequence of values stored in total during the loop and explain why the final output is 10.
Show the cumulative values rather than only listing the loop variable.
Students type their answer here.
Trace the condition-controlled loop. Include the final condition check that stops repetition where the table requires it.
Re-evaluate `number > 2` after every update. Integer division discards the fractional part.
Use one row for each pass through the loop. Fill in a box only when that value changes on that row, and leave the rest blank.
number = 20steps = 0while number > 2number = number DIV 2steps = steps + 1endwhileprint(number)print(steps)
| Row | number | steps | number > 2 | Output |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 |
What two values are printed by the condition-controlled algorithm, in order?
- A1 then 4
- B2 then 4
- C20 then 0
- D2 then 3
Complete the trace table for the loop containing selection.
Test each value for a remainder of zero. count changes only on even values.
Use one row for each pass through the loop. Fill in a box only when that value changes on that row, and leave the rest blank.
values = [3, 8, 5, 10]count = 0for each value in valuesif value MOD 2 == 0 thencount = count + 1endifnext valueprint(count)
| Row | values | count | value | value MOD 2 == 0 | Output |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 | |||||
| 7 | |||||
| 8 |
A student changes count = count + 1 to count = 1 in the final algorithm. Explain how this changes the result and name the programming idea that has been lost.
Compare replacing a value with building a running count.
Students type their answer here.
Describe a systematic method for tracing an algorithm that contains a loop and selection.
Give at least three ordered actions a student can follow under exam conditions.
Students type their answer here.
Block A checkpoint
You should now be able to define a problem, design and refine an algorithm, write runnable Python using sequence, selection and both loop types, and trace the state of an algorithm. When stuck, return to the same question: what value changes on this exact step?