Tracing a program

About this lesson: Tracing a program

In short

A trace table records the value of every variable after each line runs. It is how programmers check an algorithm by hand. Step through and fill the table in your head first.

Tracing a program

What you'll explore

Trace tables: Be the computer
A trace table records the value of every variable after each line runs. It is how programmers check an algorithm by hand.
Tracing a WHILE loop: When does it stop?
With a WHILE loop, the condition is checked before every repeat. Trace it to find how many times it runs and what it outputs.
Finding errors: Runs fine, wrong answer
This program should add the numbers 1 to 5 and print 15. It runs without crashing, but prints the wrong total: a logic error.
Test data: Try to break it
A good tester tries every kind of input: normal, boundary, erroneous and the wrong type.
Check yourself: Trace it
x = 2 for i in range(3): x = x * 2 print(x)

Also in this lesson

  • Traces written out
  • Watch out for these
  • Getting full marks on traces
  • When is a bug cheapest to fix?
  • More than the lesson
  • Stretch your brain
  • Bug hunting

Words to know

trace table
A table showing variable values as an algorithm runs.
dry run
Tracing an algorithm by hand, without a computer.
syntax error
Code that breaks the rules of the language, so it won't run.
logic error
Code that runs but gives the wrong result.
runtime error
An error that crashes the program while it runs.
normal data
Typical input that should be accepted.
boundary data
Input at the edge of what is allowed.
erroneous data
Input that should be rejected.
test plan
A list of tests with their data and expected results.
debugger
A tool that runs code step by step to find errors.

Sources

  • BBC Bitesize, GCSE Computer Science: Trace tables and testing
  • Smithsonian National Museum of American History: the 1947 'first bug' logbook
  • Isaac Computer Science: Testing and errors
  • IBM Systems Sciences Institute (widely quoted): relative cost of fixing defects

An interactive lesson with a live experiment: move the sliders, press the buttons and answer quick questions. 5 short steps and a 8-question quiz. Part of the Family plan. Written and checked by Shalo Lab. Last updated 10 November 2026.

← Loops: counting and totalling

All lessons in Term 1 · Computing · Age 14