Trace Tables: Teaching Beginners to Run Code on Paper
A student shows me a loop that should add the numbers from 1 to 10 and prints 45 instead of 55. I ask what the variable total holds after the third pass. She guesses. Then she guesses again.

A student shows me a loop that should add the numbers from 1 to 10 and prints 45 instead of 55. I ask what the variable total holds after the third pass. She guesses. Then she guesses again. She has been running the program over and over, changing a < to <= and back, hoping the output turns right. She cannot see what the code does between the first line and the last.
That gap, between reading code and knowing what it does step by step, is the most common reason beginners in my contest group get stuck. The cheapest tool I know for closing it is a trace table: a grid on paper where you run the program by hand, one line at a time, writing every variable change. It feels slow and old-fashioned. It works better than almost anything else I have tried in eleven years of coaching.
Why beginners cannot see their own code run
Experienced programmers carry a mental model of the machine. When they read x = x + 1 they picture a slot that held 3 and now holds 4. Beginners often read the same line as a statement of fact, closer to algebra, where x = x + 1 looks like nonsense. Research on novice misconceptions keeps finding the same few errors: thinking a variable can hold two values at once, thinking assignment links two variables forever, thinking the loop body runs once and the loop just "knows" the answer.
Running the program does not fix these beliefs, because the computer hides every step that matters. You see the final print and nothing in between. A debugger shows the steps, but beginners click "step over" so fast that the values blur past. Writing values down by hand forces a pause at every line. That pause is where the misconception shows up, usually as a moment where the student writes something and then says "wait".
How a trace table works
Draw one column for the line number, one column per variable, and one column for output. Each row is one executed line. When a value changes, write the new value in that row. When it does not change, leave the cell blank, so the eye only catches changes.
Here is the 1 to 10 loop my student wrote, shortened to three passes so it fits on a page:
total = 0i = 1while i < 10: total = total + i i = i + 1print(total)
| Line | total | i | i < 10? | Output |
|---|---|---|---|---|
| 1 | 0 | |||
| 2 | 1 | |||
| 3 | True | |||
| 4 | 1 | |||
| 5 | 2 | |||
| 3 | True | |||
| 4 | 3 | |||
| 5 | 3 | |||
| ... | 45 | 10 | False | |
| 6 | 45 |
She filled in the first eight rows herself. At the row where i reaches 10 and the condition reads False, she stopped writing and said "it never adds the ten". She found the bug in under four minutes, after twenty minutes of guessing at the keyboard. More important, she could explain why <= fixes it, which she could not before.
Notice the condition column. Many teachers leave it out. I always include it for loops and if statements, because the moment a condition flips is exactly where off-by-one errors live.
The advice I push back on: "just use print statements"
Every forum thread about beginner debugging ends with someone saying: forget paper, add print calls and look. For experienced coders that is good advice. For a student in her first six weeks, I think it is premature.
Print debugging only helps if you already know what you expect to see. A beginner adds print(total), gets a column of numbers, and has no prediction to compare them against. The numbers look plausible, so she moves on. A trace table makes her commit to a prediction for each row before the computer confirms or contradicts it. The learning happens in the mismatch.
So my order is: trace by hand first, predict the output, then run the program, then add prints to check the rows where hand and machine disagree. Prints become a way to test a guess rather than a way to avoid making one. Once a student does this reliably, usually after three or four weeks, I let them drop the paper for short programs.
I will admit a limit here. Trace tables get painful past about 25 rows, and they are close to useless for code with deep recursion or large lists. For those, I switch to tracing only the first two calls or the first three items, then asking the student to predict the pattern.
Running trace tables in a club session
Here is the format I use in a 60-minute session with 12 to 18 students of mixed level.
Spend the first 10 minutes tracing one short program together on the whiteboard, with students calling out each row. Choose code with one deliberate surprise, such as a variable reassigned inside an if block. Then hand out a sheet with three programs of rising difficulty: a plain loop of 5 or 6 lines, a loop with an if inside, and a function called twice with different arguments. Pairs trace them on paper for 25 minutes. Only after a pair has written its predicted output do they get to type the code and run it.
The last 15 minutes go to wrong predictions. I ask pairs who got one wrong to put the row where their table went off on the board. These are the best moments in the session, because the class sees a real misconception and the fix in one place.
Two practical details. Print the grid ahead of time with column headings blank, so students decide which variables need columns; deciding that is half the skill. And keep each program under 10 lines. Longer code turns tracing into copying.
Trace tables pair well with Parsons problems, where students reorder shuffled lines. Trace one correct ordering and one wrong ordering and compare the tables. When a student brings you a bug outside the session, ask for the trace before you look at the code; my notes on helping a beginner debug without fixing it for them explain why that question matters more than the answer. Other session ideas live in the teaching code section.
FAQ
What age can students start using trace tables?
Around 11 or 12 works well with short programs. Younger students can trace block code from Scratch if each sprite variable gets its own column.
Should trace tables include every line?
Include every executed line for the first few weeks. Later, students can skip lines that change nothing, as long as loop conditions stay in.
Are trace tables used in exams?
Yes. Several school computing exams, including UK GCSE papers, ask students to complete one, so practice pays off twice.
How long until students stop needing paper?
In my groups, most can trace short loops in their heads after three to five weeks of regular practice.
More in Teaching Code
Teaching Code
How to Teach Beginners to Read Python Documentation
I ran a small test at club last February because I was tired of a specific pattern.
Teaching Code
How to Teach the Difference Between print and return
In week five of our adult evening group, a learner called me over because her code had stopped working.
Teaching Code
How to Train Volunteer Mentors for a Coding Club
Our club recruited nine volunteers in one term. Three were still turning up by week six.