← IGCSE Computer Science Paper 2

Setting up the variable columns of a trace table

To set up a trace table, give each variable its own column in the order they first appear, then add a row each time a value changes. Leave unchanged cells blank.

Understanding Setting up the variable columns of a trace table in IGCSE Computer Science Paper 2

What it does: The columns would be Num, Sum, Count, in the same order as the DECLARE statements. The assignment gives Sum a starting value, so 0 is written in the Sum column. Later rows only change when Sum changes. Using the order of first appearance makes the table easy to match against the code, line by line. The column headings are the variable names, not their data types. A blank cell shows the value is unchanged. Writing 0 would wrongly suggest Total was reset. Adding a row for each change lets you follow the algorithm step by step. Columns follow the order the variables first appear in the algorithm.

Common mistakes: Assignment uses ←, not =. In Cambridge pseudocode = is a comparison. Total ← 0 sets the starting value, which goes in the first row of the Total column. A FOR loop sets its counter with ←, so it should be FOR Count ← 1 TO 3. The loop counter Count gets its own column in the trace table, and its starting value 1 goes in the first row.

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 71–82) and word search (Modules 71–92).

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 Total, Count and Average?
One column for each variable: three columnsOne column only, shared by all three variables
Matches
A trace table with only one column, Total, for an algorithm that declares Total, Count and Num
↓
Count and Num have no columns. Each variable must have its own column.
Applying
Meanings
Term
one column per variable
Meaning
To set up a trace table, give each variable its own column in the order they first appear, then add a row each time a value changes. Leave unchanged cells blank.
Practice
DECLARE Total : INTEGER
Testing
Gaps
Columns: Total | | OUTPUT
Check Answer
Spots
2DECLARE Count : INTEGER
3Total = 0

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

The 'Walrus' badge — Method 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 Total, Count and Average?
A. One column only, shared by all three variables
B. One column for each variable: three columns ✓
Each variable gets its own column so you can follow how its value changes.
2. In what order should the variable columns be placed in a trace table?
A. The order the variables first appear in the algorithm ✓
B. Alphabetical order of the variable names
Using the order of first appearance makes the table easy to match against the code, line by line.
3. An algorithm has DECLARE Num : INTEGER and DECLARE Total : INTEGER. What goes in the column headings?
A. Num and Total ✓
B. INTEGER and INTEGER
The column headings are the variable names, not their data types.
4. A FOR loop uses the counter variable i. Should the trace table include a column for i?
A. Yes, the loop counter is a variable and needs its own column ✓
B. No, loop counters are handled by the loop so they are left out
A loop counter changes value on each repeat, so it needs a column to show each value.
5. A new row is made and Total does not change in that step. What should you put in the Total cell?
A. Write 0 in the cell
B. Leave the cell blank ✓
A blank cell shows the value is unchanged. Writing 0 would wrongly suggest Total was reset.

Match the Pairs

DECLARE Total : INTEGER → Total needs its own column in the trace table, placed in the order the variable first appears
FOR Count ← 1 TO 4 → The loop counter Count also gets its own column, and its value changes on each pass of the loop
Variables are listed as columns in the order they first appear in the algorithm → DECLARE Num : INTEGER DECLARE Sum : INTEGER DECLARE Count : INTEGER
A starting value is entered in the first row of the variable's column → Sum ← 0
A trace table with only one column, Total, for an algorithm that declares Total, Count and Num → Count and Num have no columns. Each variable must have its own column.
Row 1: Count = 1, Total = 5 Row 2: Count = 1, Total = 5 (Count repeated) → Count is written again even though it did not change. The cell should be left blank.

Key Term

one column per variable
To set up a trace table, give each variable its own column in the order they first appear, then add a row each time a value changes. Leave unchanged cells blank.

Fill in the Blanks

1. DECLARE Total : INTEGER DECLARE Count : INTEGER Columns: Total | Count | OUTPUT
Hint: Type the name of the second declared variable, which gets the next column.
2. FOR Num ← 1 TO 3 Total ← Total + Num Columns: Num | Total | OUTPUT
Hint: Type the loop counter's name. It appears first in the algorithm, so it gets the first column.
3. DECLARE Score : INTEGER // Score gets its own trace table column
Hint: Type the keyword that lists a variable before it is used, so you know which columns to make.
4. DECLARE Total : INTEGER Total ← 0 // The Total column starts at 0
Hint: Type the variable being given a starting value, which becomes the first entry in its column.
5. Count ← Count + 1 // Total unchanged: leave its cell blank
Hint: Type the word for how you leave a trace table cell when its variable's value has not changed.

Spot the Error

Question 1
A DECLARE Total : INTEGER
B DECLARE Count : INTEGER
C Total = 0
D Count ← 0
Line C — Assignment uses ←, not =. In Cambridge pseudocode = is a comparison. Total ← 0 sets the starting value, which goes in the first row of the Total column.
Question 2
A DECLARE Num : INTEGER
B DECLARE Total : INTEGER
C Total ← 0
D FOR Count = 1 TO 3
E INPUT Num
F NEXT Count
Line D — A FOR loop sets its counter with ←, so it should be FOR Count ← 1 TO 3. The loop counter Count gets its own column in the trace table, and its starting value 1 goes in the first row.
Question 3
A // Total ← 0 then Num ← 4
B Num | Total | OUTPUT
C 0 | |
D | 4 |
Line B — Columns go in the order the variables first appear in the algorithm. Total is set before Num, so the header should be Total | Num | OUTPUT.
Question 4
A DECLARE Score : INTEGER
B DECLARE Name STRING
C INPUT Name
D INPUT Score
Line B — A DECLARE needs a colon between the identifier and its data type: DECLARE Name : STRING. Every DECLAREd variable then gets its own trace table column.
Question 5
A // Count ← 1, OUTPUT Count
B Count | OUTPUT
C 1 |
D 1 | 1
Line D — Count does not change when it is output, so its cell should be left blank: ' | 1'. Only write a value in a cell when that variable changes.

Student with a class code? Join your class →