Assignment with the ← operator

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Assignment with the ← operator

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line stores the value 0 in the variable Counter?
A Counter ← 0
B 0 ← Counter
2. In Counter ← 5, which way does the arrow point?
A Towards 5, the value being stored
B Towards Counter, the variable receiving the value
3. True or false: Total ← 10 means 'Total is equal to 10', like an equation.
A True: it states that Total equals 10
B False: it stores 10 in Total
4. Counter ← 3 is followed by Counter ← 7. What is the value of Counter afterwards?
A 7
B 10
5. Which assignment is written correctly in Cambridge pseudocode?
A Score ← 100
B 100 ← Score

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Counter ← 0 ACounter ← Counter + 1
2Score ← 10 Score ← 15 BTotal ← 25
3The arrow points to the variable that receives the value, so the variable goes on the left CUses = instead of the ← assignment operator. Cambridge pseudocode stores a value with ←, so it should be Counter ← 0.
4The ← operator means 'store this value', it is not the same as = in a maths equation. It adds 1 to the old value, then stores the result DThe arrow points the wrong way round: the value is on the left and the variable is on the right. A value cannot receive a value. It should be Counter ← 0.
50 ← Counter EStores the value 0 in the variable Counter, so the counter starts at zero
6Counter = 0 FScore ends up holding 15, because the new value replaces the earlier value 10

Definitions

Counter ← 0

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Counter _ 0
2.
DECLARE Counter : INTEGER _______ ← 0
3.
Counter ← 0 Counter ← _______ + 1
4.
Score ← 5 _____ ← 8 OUTPUT Score
5.
Total ← 0 Total _ Total + 10

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Counter : INTEGER
B 0 ← Counter
C Counter ← Counter + 1
D OUTPUT Counter
Question 2
A DECLARE Score : INTEGER
B Score = 10
C Score ← 15
D OUTPUT Score
Question 3
A Total == 0
B Total ← Total + 5
C OUTPUT Total
Question 4
A DECLARE Lives : INTEGER
B Lives ← 3
C Lives - 1 ← Lives
D OUTPUT Lives
Question 5
A DECLARE Age : INTEGER
B Age ← 14
C OUTPUT Age
D Age := 15
E OUTPUT Age

Answer Key

Assignment with the ← operator
Section A: Quick Questions
Q1
A — Counter ← 0
Q2
B — Towards Counter, the variable receiving the value
Q3
B — False: it stores 10 in Total
Q4
A — 7
Q5
A — Score ← 100
Section B: Match the Pairs
Q1
Counter ← 0 → Stores the value 0 in the variable Counter, so the counter starts at zero
Q2
Score ← 10 Score ← 15 → Score ends up holding 15, because the new value replaces the earlier value 10
Q3
The arrow points to the variable that receives the value, so the variable goes on the left → Total ← 25
Q4
The ← operator means 'store this value', it is not the same as = in a maths equation. It adds 1 to the old value, then stores the result → Counter ← Counter + 1
Q5
0 ← Counter → The arrow points the wrong way round: the value is on the left and the variable is on the right. A value cannot receive a value. It should be Counter ← 0.
Q6
Counter = 0 → Uses = instead of the ← assignment operator. Cambridge pseudocode stores a value with ←, so it should be Counter ← 0.
Section C: Definitions
Q1
Counter ← 0 — Assignment: the value on the right of the arrow is stored in the variable on the left. Counter ← 0 stores 0 in Counter and replaces any earlier value.
Section D: Fill in the Blanks
Q1
Counter ← 0
Q2
DECLARE Counter : INTEGER Counter ← 0
Q3
Counter ← 0 Counter ← Counter + 1
Q4
Score ← 5 Score ← 8 OUTPUT Score
Q5
Total ← 0 Total ← Total + 10
Section E: Spot the Error
Q1
B — The arrow must point to the variable receiving the value. A value cannot be stored in 0. It should be Counter ← 0.
Q2
B — Cambridge pseudocode uses the ← operator for assignment. The = sign is for comparing values. It should be Score ← 10.
Q3
A — == is a comparison, not an assignment. It does not store 0 in Total. It should be Total ← 0.
Q4
C — The variable receiving the value goes on the left of the arrow and the expression on the right. It should be Lives ← Lives - 1.
Q5
D — Cambridge pseudocode does not use := for assignment. The ← operator replaces the earlier value 14 with 15. It should be Age ← 15.