← IGCSE Computer Science Paper 2

Tracing assignments to find a variable's value

A table with one column per variable. Follow the program line by line and write each variable's new value after every assignment, so you can predict the final OUTPUT.

Understanding Tracing assignments to find a variable's value in IGCSE Computer Science Paper 2

What it does: Following the assignments in order, Total changes from 4 to 12, so the final OUTPUT is 12. 47 DIV 10 is 4 and 47 MOD 10 is 7, so the trace table records Tens as 4 and Units as 7. The second line uses the old value of X (5), adds 2, and stores 7 back in X. Write 7 as the new value in the trace table. Each repeat adds 1 to the current value, so Counter goes 0, 1, 2, 3. It does not reset to 1 each time. 17 DIV 5 gives the whole number of times 5 fits, which is 3. 17 MOD 5 gives the remainder, which is 2.

Common mistakes: An assignment puts the variable on the left of the arrow and the expression on the right. When tracing, Count becomes 0 and then 1. The line should be Count ← Count + 1. DECLARE needs a colon between the identifier and its data type. It should be DECLARE Total : INTEGER. After the later lines, the trace table shows Total as 5, then 10.

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 337–346) and word search (Modules 337–357).

Take this worksheet further — free with Cloodit

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

Learning
Duo
X ← 5 then X ← X + 2. What is X after both lines?
57
Matches
Counter ← 0 Counter ← Counter + 1 Counter ← Counter + 1 OUTPUT Counter // A student traces the output as 1
↓
The student only recorded one of the two additions. Counter goes 0, then 1, then 2, so the output is 2, not 1. Every assignment needs its own new value in the trace table.
Applying
Meanings
Term
trace table
Meaning
A table with one column per variable. Follow the program line by line and write each variable's new value after every assignment, so you can predict the final OUTPUT.
Practice
Counter ← 0
Testing
Gaps
OUTPUT Counter // shows
Check Answer
Spots
2Count ← 0
3Count + 1 ← Count

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

The 'Dumbo Octopus' badge — Module Maker, 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. X ← 5 then X ← X + 2. What is X after both lines?
A. 7 ✓
B. 5
The second line uses the old value of X (5), adds 2, and stores 7 back in X. Write 7 as the new value in the trace table.
2. Counter ← 0, then Counter ← Counter + 1 runs three times. What is Counter at the end?
A. 1
B. 3 ✓
Each repeat adds 1 to the current value, so Counter goes 0, 1, 2, 3. It does not reset to 1 each time.
3. How is a trace table set up?
A. One column for each OUTPUT statement only
B. One column for each variable ✓
A trace table has one column per variable. You then add a new row value whenever an assignment changes that variable.
4. Total ← 10, Count ← 3, Total ← Total - Count, Count ← Count * 2. What are the final values?
A. Total 7, Count 6 ✓
B. Total 10, Count 6
Total changes from 10 to 7 (10 - 3). Count then changes from 3 to 6. Total keeps the value it was just given.
5. N ← 17, Q ← N DIV 5, R ← N MOD 5. What are Q and R?
A. Q = 3, R = 2 ✓
B. Q = 2, R = 3
17 DIV 5 gives the whole number of times 5 fits, which is 3. 17 MOD 5 gives the remainder, which is 2.

Match the Pairs

Counter ← Counter + 1 → Adds 1 to the current value of Counter and stores the new value back in Counter. In a trace table, write the new value in the Counter column.
Remainder ← 17 MOD 5 → Remainder gets the value 2 because 17 divided by 5 leaves 2. In a trace table, write 2 in the Remainder column.
Trace the lines in order and record each variable's new value after every assignment. After Total ← 4 and then Total ← Total * 3, Total is 12. → Total ← 4 Total ← Total * 3 OUTPUT Total
To trace DIV and MOD, work out each result on its own line. Starting with Number ← 47, Tens ← Number DIV 10 stores 4 and Units ← Number MOD 10 stores 7. → Number ← 47 Tens ← Number DIV 10 Units ← Number MOD 10
Counter ← 0 Counter ← Counter + 1 Counter ← Counter + 1 OUTPUT Counter // A student traces the output as 1 → The student only recorded one of the two additions. Counter goes 0, then 1, then 2, so the output is 2, not 1. Every assignment needs its own new value in the trace table.
X ← 5 Y ← X + 2 X ← 10 OUTPUT Y // A student traces the output as 12 → The student used the new value of X (10) to work out Y. Y was assigned when X was 5, so Y stays 7. Changing X later does not change Y.

Key Term

trace table
A table with one column per variable. Follow the program line by line and write each variable's new value after every assignment, so you can predict the final OUTPUT.

Fill in the Blanks

1. Counter ← 0 Counter ← Counter + 1 OUTPUT Counter // shows 1
Hint: Type the value Counter holds after both assignments, which is what OUTPUT displays.
2. Counter ← 3 Counter ← Counter + 1 Counter ← Counter + 1 // now 5
Hint: Trace each line in order and type the final value stored in Counter.
3. Total ← 17 Tens ← Total DIV 10 // 1 Units ← Total MOD 10 // 7
Hint: Type the operator that gives the whole number of times 10 fits into Total.
4. Total ← 17 Units ← Total MOD 5 OUTPUT Units // shows 2
Hint: Work out the remainder, then type the value that OUTPUT will display.
5. A ← 4 B ← A * 2 A ← B + 1 // A is now 9
Hint: Type the variable name whose current value makes A end up as 9 after the last assignment.

Spot the Error

Question 1
A DECLARE Count : INTEGER
B Count ← 0
C Count + 1 ← Count
D OUTPUT Count
Line C — An assignment puts the variable on the left of the arrow and the expression on the right. When tracing, Count becomes 0 and then 1. The line should be Count ← Count + 1.
Question 2
A DECLARE Total INTEGER
B Total ← 5
C Total ← Total * 2
D OUTPUT Total
Line A — DECLARE needs a colon between the identifier and its data type. It should be DECLARE Total : INTEGER. After the later lines, the trace table shows Total as 5, then 10.
Question 3
A DECLARE Level : INTEGER
B Level ← 2
C Level ← Level + 3
D OUTPUT Level // shows 6
Line C — The trace table gives Level = 2, then 2 * 3 = 6, which matches the comment. Level + 3 would give 5. The line should be Level ← Level * 3.
Question 4
A DECLARE Score : INTEGER
B Score = 10
C Score ← Score + 5
D OUTPUT Score
Line B — Cambridge pseudocode assigns a value with the ← arrow, not =. The line should be Score ← 10. Then the trace shows Score as 10 and then 15.
Question 5
A X ← 4
B Y ← X + 3 // Y is 12
C X ← Y - 2
D OUTPUT X, Y
Line B — X is 4, so X + 3 gives 7, not the 12 in the comment. The trace needs Y ← X * 3 to give 12. X then becomes 10 on the next line.

Student with a class code? Join your class →