GCSE · Computer Science · Edexcel · Spec 1CP2
Determining algorithm output
Type 6 into a program and it prints something. You could guess what. Or you could be the computer: one line at a time, writing down what changes.
Computer Science · Algorithms
Trace table — dry run the code
This program is meant to output the numbers divisible by three. The user types 6. Be the computer: run one line, write down what that line did, then run the next.
Ready when you are — step through one line at a time.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Don't guess what a program prints. Walk it, one line at a time, and write down everything that changes.
What you need to know
- A trace table tracks the values of variables and the flow of execution, step by step, as you mentally run an algorithm.
- Columns hold the important things to track (the line, the variables, the conditions and the outputs). Each row is one step of the execution.
- For each line: record any variable assignment, record True or False for any condition, and record any output.
- When a condition is False, the line it controls is skipped this time round. A while loop is revisited while its condition is True.
- % (modulo) gives the remainder, so 14 % 4 is 2. // (integer division) gives the whole number of times, so 15 // 4 is 3.
- Trace tables work on flowcharts, pseudocode and program code. They give a clear step-by-step view and help pinpoint logic errors, but they're open to human error and impractical for complex algorithms.
The big picture
To find an algorithm's output, you trace it: walk through it one step at a time, recording the state in a trace table. Columns track the variables, conditions and outputs, and each row is one step. You write down each assignment, each condition's True or False, and each output. A False condition skips the line it controls this time round. You'll need % (remainder) and // (whole-number division) too. The method works on flowcharts, pseudocode and code. It's clear and pinpoints errors, but it's open to human error and impractical for complex algorithms.
Key points
Worked example
Problem
Trace this program and state its output. num = 472, total = 0, then while num > 0: total = total + num % 10, and num = num // 10. After the loop: print(total).
⚠ Watch out
Stopping the trace one row too early. A while loop keeps going back to its condition while it's True, so the check that finally comes out False gets its own row (2 > 2 is False). Skip it and you can easily run the loop once too often or too few times.
Memory hook
Be the computer: one line, one row. True? Go in. False? Skip it this time round. And % is whatever's left over.
Check yourself
Trace it on paper: x = 10, then while x > 4: x = x - 3, then print(x) after the loop. What is output, and what does your last row say about the condition?
Flashcards
(14)What is a trace table?
In a trace table, what do the columns represent?
In a trace table, what does each row represent?
What is the first thing to do when using a trace table to find an output?
A line contains a condition. What goes in the trace table?
What happens to the line controlled by a condition that is False?
When is a while loop revisited?
What does the % (modulo) operator give?
What does the // (integer division) operator give?
What is the test num % 3 == 0 checking?
Can trace tables only be used on pseudocode?
Why is walking through an algorithm useful?
Give two advantages of trace tables.
Give two limitations of trace tables.
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 29 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.