Home  ➔  Guides & Articles  ➔  Trace Table Guide

How to Complete a Trace Table: Step-by-Step Guide & Worked Examples

Cambridge IGCSE 0478 / A-Level 9618 Updated July 2026 • 8 min read

In Cambridge Computer Science exams (Paper 2), trace tables are worth up to 20% of your practical problem-solving mark. A trace table allows you to "dry run" an algorithm line-by-line, tracking how variable values change as loops execute and conditions are evaluated.

🎯 What You Will Learn in This Guide:

  • The 3 golden rules of Cambridge trace table scoring.
  • How to structure trace table column headers (Variables, Conditions, Outputs).
  • 3 step-by-step worked examples (Counter loops, Array searches, Nested loops).
  • How to practice with interactive trace table auto-grading online.

The 3 Golden Rules of Trace Tables

Examiners grade trace tables using a strict line-by-line mark scheme. To get full marks every time, strictly follow these rules:

  1. Only record a value when it changes: Do NOT repeat the previous value in subsequent rows if a variable hasn't changed. Leave that cell empty!
  2. Follow exact execution order: Write values row-by-row as each instruction executes. Do not skip lines or jump ahead.
  3. Log output exactly: Write strings, numbers, or prompt outputs in the OUTPUT column precisely as printed by the algorithm.

Example 1: Tracing a FOR Loop (Counter & Accumulator)

Consider this simple pseudocode algorithm that calculates the sum of numbers from 1 to 4:

DECLARE Count, Sum : INTEGER Sum 0 FOR Count 1 TO 4 Sum Sum + Count NEXT Count OUTPUT "Total Sum = ", Sum

Completed Trace Table Solution:

Line # Count Sum OUTPUT
2 0
3 1
4 1
5 (Iteration 2) 2 3
5 (Iteration 3) 3 6
5 (Iteration 4) 4 10
6 Total Sum = 10

💡 Notice how cell values are only filled when Sum or Count is modified!

Example 2: Tracing an Array Search with WHILE Loop

This algorithm searches an array Scores[1:4] containing [12, 45, 8, 90] to count how many scores are greater than 20:

DECLARE Scores : ARRAY[1:4] OF INTEGER // Scores = [12, 45, 8, 90] DECLARE Index, HighCount : INTEGER Index 1 HighCount 0 WHILE Index <= 4 DO IF Scores[Index] > 20 THEN HighCount HighCount + 1 ENDIF Index Index + 1 ENDWHILE OUTPUT "High Scores: ", HighCount

Completed Trace Table Solution:

Index HighCount Scores[Index] > 20 OUTPUT
1 0 FALSE (12)
2 1 TRUE (45)
3 FALSE (8)
4 2 TRUE (90)
5 High Scores: 2

Practice Trace Tables Online

Use our interactive trace table generator with automated step-by-step validation.

📊 Trace Table Questions ⚡ Trace Table Workspace

Example 3: Tracing a REPEAT...UNTIL Post-Condition Loop

In a post-condition loop, the loop body always executes at least once before the condition is checked.

DECLARE Num, Product : INTEGER Num 2 Product 1 REPEAT Product Product * Num Num Num + 3 UNTIL Product > 20 OUTPUT Product

Completed Trace Table Solution:

Num Product Product > 20 OUTPUT
2 1
5 2 FALSE (2)
8 10 FALSE (10)
11 80 TRUE (80)
80

Common Mistakes to Avoid in Cambridge Exams

  • Mistake 1: Filling values in empty cells when variables haven't changed.
  • Mistake 2: Forgetting the final value of loop counter when loop terminates (e.g., in a FOR i ← 1 TO 5 loop, i equals 6 after loop ends).
  • Mistake 3: Omitting variable quotes in text outputs or misinterpreting operator precedence like MOD and DIV.

Next Steps & Related Resources