GCSE · Computer Science · Edexcel · Spec 1CP2
Trace tables
Can you tell by looking at code how many times a loop runs and what it prints? It's easy to get wrong. A trace table turns the guess into proof.
Computer Science · Algorithms
Trace table — dry run the code
Be the computer. Before each click, guess which cell gets filled next — then check.
Ready when you are — step through one line at a time.
Predict, then check
Trace it in your head, or on scrap paper, before you commit.
count starts at 0. A while loop keeps running while count != 10 (while count is not equal to 10), and every pass adds 4 to count. What happens?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Run an algorithm by hand, one step at a time, and find out what it really does.
What you need to know
- Set up a trace table with the columns a particular algorithm needs.
- Fill it in one execution step at a time, updating each variable from its current value.
- Record every loop-condition result and use it to say when — or whether — a loop stops.
- Explain why programmers use trace tables, and their main limitation.
The big picture
A trace table lets you run an algorithm by hand, without a computer. Its columns hold what you're tracking — the line number, each variable, each condition and the output — and each row is one step the algorithm actually takes. You write a value only when it changes, or when a condition or output is evaluated, and you record every True or False from a loop condition. The finished table shows what the algorithm does, reveals a loop that never ends and helps pinpoint logic errors — but because it's filled in by hand, it can contain mistakes of its own.
Key points
Worked example
Problem
Trace this algorithm and give its output. Line 1: stock = 14 · Line 2: sold = 0 · Line 3: while stock >= 5: · Line 4: stock = stock - 5 · Line 5: sold = sold + 1 · Line 6: print(stock). Lines 4 and 5 are inside the loop.
⚠ Watch out
Giving each line of code one row. A line inside a loop runs again on every pass, so it needs a new row every time — and that includes every check of the loop condition, not just the first.
Memory hook
Be the computer: one step, one row. Look it up, work it out, write it down — and the loop only stops when the condition says False.
Check yourself
Trace x = 1, then while x < 30: x = x * 3. How many condition checks happen, and what is x at the end? (5 checks: four True, one False. x = 81.)
Flashcards
(13)What is a trace table?
What does a trace table record at each step?
What do the columns of a trace table show?
What does each row of a trace table represent?
When do you write a value in a column?
How do you trace the line total = total + 7?
When is a while loop's condition checked?
When does a while loop stop?
How does a trace table show a loop that never ends?
A loop's counter jumps over the value its condition is waiting for. How can you fix it?
How does a trace table help find logic errors?
Why does a trace table help you understand an algorithm?
What is the main limitation 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.