← IGCSE Computer Science Paper 2

Assigning the result of an expression

The expression on the right is worked out first, then its result is stored in the variable on the left, replacing any old value that variable held.

Understanding Assigning the result of an expression in IGCSE Computer Science Paper 2

What it does: The right-hand side can be just another variable. Its current value is copied into BackupScore, and Score keeps its value. Length * Width is worked out first, then the result is stored in Area on the left of the arrow. The old value 4 is used on the right to work out 4 + 1 = 5. Then 5 replaces the old value in Counter.

Common mistakes: The variable being assigned to must be on the left of the arrow and the value on the right. It should be Rate ← 12.5. The expression must use the variable Counter, whose old value is read and then replaced. Count was never declared or given a value. It should be Counter ← Counter + 1.

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 317–326) and word search (Modules 317–336).

Take this worksheet further — free with Cloodit

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

Learning
Duo
In TotalToPay ← NumberOfHours * HourlyRate, what happens first?
NumberOfHours * HourlyRate is worked outTotalToPay is given its value before anything is calculated
Matches
NumberOfHours * HourlyRate ← TotalToPay
↓
The arrow is the wrong way round. The variable that receives the result must be on the left and the expression on the right: TotalToPay ← NumberOfHours * HourlyRate.
Applying
Meanings
Term
TotalToPay ← NumberOfHours * HourlyRate
Meaning
The expression on the right is worked out first, then its result is stored in the variable on the left, replacing any old value that variable held.
Practice
NumberOfHours ← 8
Testing
Gaps
TotalToPay ← NumberOfHours HourlyRate
Check Answer
Spots
1Hours ← 8
212.5 ← Rate

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

The 'Red Panda' badge — Forest Explorer, 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. In TotalToPay ← NumberOfHours * HourlyRate, what happens first?
A. TotalToPay is given its value before anything is calculated
B. NumberOfHours * HourlyRate is worked out ✓
The expression on the right is always evaluated first. Its result is then stored in the variable on the left.
2. Which line stores the result of a calculation in TotalToPay?
A. TotalToPay ← NumberOfHours * HourlyRate ✓
B. NumberOfHours * HourlyRate ← TotalToPay
The variable that receives the value goes on the left of the arrow. The expression goes on the right.
3. Counter currently holds 4. What does Counter hold after Counter ← Counter + 1 ?
A. 5 ✓
B. 4
The old value 4 is used on the right to work out 4 + 1 = 5. Then 5 replaces the old value in Counter.
4. Which statement describes Counter ← Counter + 1 correctly?
A. It is impossible because Counter appears on both sides
B. It uses the old value of Counter, then replaces it with the new result ✓
A variable may appear on both sides. The right side is worked out with the old value, then the answer is stored back in the variable.
5. HourlyRate holds 8 and NumberOfHours holds 5. After TotalToPay ← NumberOfHours * HourlyRate, what do the variables hold?
A. TotalToPay is 40, and NumberOfHours and HourlyRate are unchanged ✓
B. TotalToPay is 40, and NumberOfHours and HourlyRate are now 0
Only the variable on the left changes. The variables on the right are just read, so they keep their values.

Match the Pairs

TotalToPay ← NumberOfHours * HourlyRate → Works out NumberOfHours multiplied by HourlyRate first, then stores the result in TotalToPay
Counter ← Counter + 1 → Takes the current value of Counter, adds 1, then stores the new value back in Counter, replacing the old one
Copying the value of one variable into another variable → BackupScore ← Score
The expression on the right is calculated before anything is stored in the variable on the left → Area ← Length * Width
NumberOfHours * HourlyRate ← TotalToPay → The arrow is the wrong way round. The variable that receives the result must be on the left and the expression on the right: TotalToPay ← NumberOfHours * HourlyRate.
Counter + 1 ← Counter → The expression is on the left of the arrow, so the result has nowhere to be stored. It should be Counter ← Counter + 1.

Key Term

TotalToPay ← NumberOfHours * HourlyRate
The expression on the right is worked out first, then its result is stored in the variable on the left, replacing any old value that variable held.

Fill in the Blanks

1. TotalToPay ← NumberOfHours * HourlyRate
Hint: Type the arithmetic operator that multiplies the two values.
2. Counter ← 5 Counter ← Counter + 1 OUTPUT Counter
Hint: Type the variable whose old value is used on the right before it is replaced.
3. Lives ← 3 Lives ← Lives - 1
Hint: Type the operator that takes one away from the old value.
4. Score ← 10 Backup ← Score
Hint: Type the variable whose value is copied into Backup.
5. Total ← Price * Quantity
Hint: Type the assignment operator that stores the result of the expression in the variable.

Spot the Error

Question 1
A Hours ← 8
B 12.5 ← Rate
C Total ← Hours * Rate
D OUTPUT Total
Line B — The variable being assigned to must be on the left of the arrow and the value on the right. It should be Rate ← 12.5.
Question 2
A Counter ← 0
B Counter ← Counter + 1
C Counter ← Count + 1
D OUTPUT Counter
Line C — The expression must use the variable Counter, whose old value is read and then replaced. Count was never declared or given a value. It should be Counter ← Counter + 1.
Question 3
A Hours = 6
B Rate ← 11.5
C TotalToPay ← Hours * Rate
Line A — Cambridge pseudocode assigns with the ← arrow, not the = sign. It should be Hours ← 6.
Question 4
A Length ← 5
B Width ← 3
C Area ← Length * Width
D Perimeter ← 2 * Length + Width
Line D — Multiplication is worked out before addition, so this only doubles Length. Brackets are needed so the expression is Perimeter ← 2 * (Length + Width).
Question 5
A First ← 10
B Second ← 20
C First ← Backup
D OUTPUT Backup
Line C — To copy First into Backup, the variable receiving the value goes on the left. Here Backup has no value yet and First would be overwritten. It should be Backup ← First.

Student with a class code? Join your class →