← IGCSE Computer Science Paper 2

Completing a trace table for pseudocode

A table used to dry-run pseudocode: one column per variable plus OUTPUT, and a new row each time a statement changes a value. INPUT values come from the question.

Understanding Completing a trace table for pseudocode in IGCSE Computer Science Paper 2

What it does: This statement changes Total, so Total gets a new value in the table. Other columns stay blank on that row because nothing in them changed. Anything produced by an OUTPUT statement is written in the OUTPUT column, not in a variable column. In an exam, the INPUT values are supplied by the question, so you must use exactly those values in order. An assignment changes a variable, so it needs a row. A comment does nothing and is never traced. OUTPUT sends text to the screen, so it goes in the OUTPUT column. It does not change Total. Headings come from the variables in the algorithm, plus an OUTPUT column. Add a prompt column if the algorithm asks for input.

Common mistakes: Total must add Count to its own old value. Count + Count gives 2, 4, 6 in the Total column instead of 1, 3, 6. It should be Total ← Total + Count. Pseudocode keywords must be in upper case. It should be INPUT Num. The value the question supplies is then written in the Num column of the trace table.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 216–231) and word search (Modules 188–231).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
How many columns does a trace table need for the variables in an algorithm?
One column for each variableOne column for the whole algorithm
Matches
Trace table has columns for Count and Total only, but the algorithm uses OUTPUT Total
↓
The OUTPUT column is missing, so there is nowhere to record what the algorithm displays.
Applying
Meanings
Term
trace table
Meaning
A table used to dry-run pseudocode: one column per variable plus OUTPUT, and a new row each time a statement changes a value. INPUT values come from the question.
Practice
// Trace columns: Total, Count, Number, OUTPUT
Testing
Gaps
Num | Total |
Check Answer
Spots
2FOR Count ← 1 TO 3
3 Total ← Count + Count

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Cosmic Dragon' badge — Orbit Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. How many columns does a trace table need for the variables in an algorithm?
A. One column for each variable ✓
B. One column for the whole algorithm
Each variable gets its own column so you can follow how its value changes as you dry-run the code.
2. Where does a trace table show what the algorithm displays on screen?
A. In an OUTPUT column ✓
B. In the column of the last variable
Anything produced by an OUTPUT statement is written in the OUTPUT column, not in a variable column.
3. The question says the user types 7 and then 12. What do you do when you reach INPUT Num?
A. Choose any numbers you like
B. Use the values given in the question ✓
In an exam, the INPUT values are supplied by the question, so you must use exactly those values in order.
4. Which statement should get a new row in a trace table?
A. Total ← Total + 5 ✓
B. // Add the numbers
An assignment changes a variable, so it needs a row. A comment does nothing and is never traced.
5. Total is 10 and Count is 2. The statement Total ← Total + 4 runs. What do you write in the new row?
A. Write 14 under Total and 14 under Count
B. Write 14 under Total and leave Count blank ✓
Only fill in the cell for the value that changes. Count stays the same, so its cell is left empty.

Match the Pairs

| Count | Total | OUTPUT | → The header row of a trace table: one column for each variable (Count, Total) plus an OUTPUT column.
INPUT Num (value given: 7) → Take the next value supplied by the question and write it in the Num column on a new row.
Only write a new value in a column when that statement changes the variable → Total ← Total + Num
Anything printed by the algorithm is written in the OUTPUT column → OUTPUT Total
Trace table has columns for Count and Total only, but the algorithm uses OUTPUT Total → The OUTPUT column is missing, so there is nowhere to record what the algorithm displays.
Row for Count ← Count + 1 also rewrites the Total and Num values, which did not change → Values are copied into columns for variables that did not change on that statement.

Key Term

trace table
A table used to dry-run pseudocode: one column per variable plus OUTPUT, and a new row each time a statement changes a value. INPUT values come from the question.

Fill in the Blanks

1. Num | Total | OUTPUT
Hint: Type the trace table column heading that records what the program displays.
2. Total ← 0 Total ← Total + 4 Row 2: Total = 4
Hint: Type the value held in the Total column after the second statement runs.
3. INPUT Score // the question supplies the value 60
Hint: Type the keyword that reads a value, which a dry-run takes from the question.
4. Count ← 3 OUTPUT Count OUTPUT row: Count unchanged = 3
Hint: Type the value Count keeps in the row, because OUTPUT does not change any variable.
5. // Total was 0, Num is 4, now Total is 4 Total ← Total + Num
Hint: Type the arithmetic operator that changes Total in the table from its old value to its new one.

Spot the Error

Question 1
A Total ← 0
B FOR Count ← 1 TO 3
C Total ← Count + Count
D NEXT Count
E OUTPUT Total
Line C — Total must add Count to its own old value. Count + Count gives 2, 4, 6 in the Total column instead of 1, 3, 6. It should be Total ← Total + Count.
Question 2
A input Num
B Total ← Num * 2
C OUTPUT Total
Line A — Pseudocode keywords must be in upper case. It should be INPUT Num. The value the question supplies is then written in the Num column of the trace table.
Question 3
A Total ← 10
B WHILE Total > 0 DO
C Total ← Total + 5
D ENDWHILE
E OUTPUT Total
Line C — Total goes 15, 20, 25 and never reaches 0, so the trace table never finishes. It should be Total ← Total - 5, giving rows 10, 5, 0.
Question 4
A Total = 0
B Num ← 4
C Total ← Total + Num
D OUTPUT Total
Line A — Assignment uses ←, not =. Without it Total is never given the value 0, so the first row of the Total column would be empty. It should be Total ← 0.
Question 5
A Num ← 3
B Num * 2 ← Num
C Num ← Num + 1
D OUTPUT Num
Line B — The variable being changed goes on the left of ←, and the calculation goes on the right. It should be Num ← Num * 2. The Num column gets a new value of 6 in this row.

Student with a class code? Join your class →