← IGCSE Computer Science Paper 2

Tracing assignments and arithmetic

When tracing, work out the right side using the current values, then write the result in that variable's column. The old value is used first, then replaced by the new one.

Understanding Tracing assignments and arithmetic in IGCSE Computer Science Paper 2

What it does: The old value (4) is used on the right side, and the result (5) becomes the new value of Counter. Only the variable on the left of the arrow changes. Total becomes 27, while Value is only read and stays the same. Use the current value first: 4 + 1 = 5. The 5 replaces the 4 in the Counter column. Work out the right side with the current values: 10 + 7 = 17. Then store 17 in Total. Each run adds 1 to the current value: 0, then 1, then 2, then 3. 48 + 79: add the units, 8 + 9 = 17, write 7 and carry 1. Then 4 + 7 + 1 = 12. The answer is 127.

Common mistakes: The variable being assigned to must be on the left of the arrow. It should be Counter ← 0, so the trace table starts with Counter as 0. The program should output Total, which holds the running sum (8 after the trace). Value only holds the number that was added. It should be OUTPUT Total.

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 83–92) 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
Counter is 4. The line Counter ← Counter + 1 runs. What do you write in the Counter column?
51
Matches
Counter is 3. For Counter ← Counter + 1 the student writes 1 in the Counter column.
↓
The student ignored the old value of Counter and only used the 1. They should work out 3 + 1 and write 4.
Applying
Meanings
Term
Counter ← Counter + 1
Meaning
When tracing, work out the right side using the current values, then write the result in that variable's column. The old value is used first, then replaced by the new one.
Practice
Counter ← 0
Testing
Gaps
Counter ← + 1
Check Answer
Spots
10 ← Counter
2Counter ← Counter + 1

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

The 'Rhinoceros' badge — Thick-Skinned Coder, 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. Counter is 4. The line Counter ← Counter + 1 runs. What do you write in the Counter column?
A. 5 ✓
B. 1
Use the current value first: 4 + 1 = 5. The 5 replaces the 4 in the Counter column.
2. Total is 10 and Value is 7. The line Total ← Total + Value runs. What is the new Total?
A. 7
B. 17 ✓
Work out the right side with the current values: 10 + 7 = 17. Then store 17 in Total.
3. Which order is correct when you trace an assignment?
A. Work out the right side using the old values, then store the result ✓
B. Store the new value first, then work out the right side
The right side is always calculated first using the values the variables hold right now. Only then is the answer stored.
4. Counter starts at 0. Counter ← Counter + 1 runs three times. What is Counter at the end?
A. 3 ✓
B. 1
Each run adds 1 to the current value: 0, then 1, then 2, then 3.
5. In Total ← Total + Value, which column changes when the line runs?
A. Both Total and Value change.
B. Only Total changes. Value stays the same. ✓
The variable on the left of the arrow is the only one that gets a new value. Value is only read.

Match the Pairs

Counter ← Counter + 1 → Take the current value of Counter, add 1, then store the new value back in the Counter column of the trace table.
Total ← Total + Value → Add the current Value to the current Total, then write the answer in the Total column as the new running total.
Counter is 4 before this line runs. Working out the right side gives 4 + 1, so 5 is written in the Counter column. → Counter ← Counter + 1
Total is 20 and Value is 7. Work out 20 + 7 by hand, then write 27 in the Total column. Value stays 7. → Total ← Total + Value
Counter is 3. For Counter ← Counter + 1 the student writes 1 in the Counter column. → The student ignored the old value of Counter and only used the 1. They should work out 3 + 1 and write 4.
Total is 12 and Value is 5. For Total ← Total + Value the student writes 5 in the Total column. → The student replaced Total with Value instead of adding them. The correct sum is 12 + 5, so 17 goes in the Total column.

Key Term

Counter ← Counter + 1
When tracing, work out the right side using the current values, then write the result in that variable's column. The old value is used first, then replaced by the new one.

Fill in the Blanks

1. Counter ← 0 Counter ← Counter + 1
Hint: Type the variable whose current value is used on the right-hand side to add 1 to itself.
2. Total ← 10 Total ← Total + 5 // Total is now 15
Hint: Type the number stored in Total after the second line has run.
3. Total ← 0 Total ← Total + Value
Hint: Type the arithmetic operator that adds the new Value to the running total.
4. Counter ← 4 Counter ← Counter + 1 // Old value was 4, new value is 5
Hint: Type the value Counter held before the second line replaced it.
5. Total ← 12 Value ← 7 Total ← Total + Value
Hint: Type the variable name whose column receives the result of the sum.

Spot the Error

Question 1
A 0 ← Counter
B Counter ← Counter + 1
C Counter ← Counter + 1
D OUTPUT Counter
Line A — The variable being assigned to must be on the left of the arrow. It should be Counter ← 0, so the trace table starts with Counter as 0.
Question 2
A Total ← 0
B Value ← 8
C Total ← Total + Value
D OUTPUT Value
Line D — The program should output Total, which holds the running sum (8 after the trace). Value only holds the number that was added. It should be OUTPUT Total.
Question 3
A Counter ← 5
B Counter = Counter + 1
C OUTPUT Counter
Line B — In Cambridge pseudocode, = is a comparison, not an assignment. Use the arrow: Counter ← Counter + 1. In a trace, the new value 6 replaces the old 5.
Question 4
A Total ← 10
B Total ← Totl + 5
C OUTPUT Total
Line B — The variable name is misspelled. Totl does not exist, so there is no current value to use. It should be Total ← Total + 5, which gives 15.
Question 5
A DECLARE Count : INTEGER
B Count ← "0"
C Count ← Count + 1
D OUTPUT Count
Line B — Count is declared as an INTEGER, so it cannot be given a STRING. The quotes make "0" text. It should be Count ← 0.

Student with a class code? Join your class →