Skip to content
Menu

Year 10 (ages 14–15, Grade 9 in the US) · Computing · GCSE programming · Lesson 14

Trace tables

Using trace tables to follow a program line by line: recording variable values and outputs through sequence, selection and loops, and using tracing to find logic errors.

Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

Whiteboard video lesson: Trace tables

9-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 the purpose of a trace table
  • Complete a trace table for a loop
  • Record output correctly
  • Use tracing to find logic errors

The method

  1. One column per variable, plus Output.
  2. Go line by line; write a new value when it changes.
  3. For loops: one row per pass.
  4. Check the final values match what should happen.

Key words: trace table, dry run, variable, output, iteration.

Worked examples

Worked examples from the lesson, with every step.

Question 1

Trace: list the values of x and the output. c:x = 2 c:while x < 20: c: x = x * 3 c:print(x)

  1. Step 1: 2, 6, 18, 54
  2. Step 2: 54 (printed after the loop)

Answer: x: 2, 6, 18, 54; output 54

Question 2

Trace: what is output? c:a = 5 c:b = 3 c:a = a + b c:b = a - b c:print(a, b)

  1. Step 1: a = 5 + 3 = 8
  2. Step 2: b = 8 − 3 = 5

Answer: 8 5

Question 3

Trace: what is output? c:count = 0 c:for n in [4, 7, 2, 9]: c: if n > 5: c: count = count + 1 c:print(count)

  1. Step 1: 4 no, 7 yes, 2 no, 9 yes
  2. Step 2: 2

Answer: 2