← Years 5–6 Creating Digital Solutions

Variables in an algorithm

A variable is a named place that stores a value. SET gives it a value, like 0, and later steps can change it, such as ADD 1 to score, so it works as a counter.

Understanding Variables in an algorithm in Years 5–6 Creating Digital Solutions

What it does: Setting lapCount to 0 gives the counter its starting value before any laps are counted. lives is first set to 3 and then changed by the next step, so it now holds 4. SET gives a variable a value. Here the variable score starts at 0. A variable is a named place that holds a value. 'lives' is a name we choose. TO is part of the SET instruction. ADD 1 to score changes the stored value so it is one bigger each time. SET replaces the old value. The variable now stores 5. That is why it is called a variable. Later steps can change what it stores.

Common mistakes: The variable was named score, but this line adds to points, which was never set. It should be ADD 1 TO score. There is no variable called scores. The variable is named score, so the line should be DISPLAY score.

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 11–20) and word search (Modules 1–20).

Take this worksheet further — free with Cloodit

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

Learning
Duo
What does SET score TO 0 do in an algorithm?
It stores the value 0 in a variable called scoreIt prints the word score on the screen
Matches
ADD 1 TO score SET score TO 0
↓
The steps are in the wrong order. The variable is changed before it has a starting value, so the counter would be reset to 0 and the count lost. SET should come first.
Applying
Meanings
Term
SET score TO 0
Meaning
A variable is a named place that stores a value. SET gives it a value, like 0, and later steps can change it, such as ADD 1 to score, so it works as a counter.
Practice
SET score TO 0
Testing
Gaps
score TO 0
Check Answer
Spots
2REPEAT 3 TIMES
3 ADD 1 TO points

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

The 'Desert Tortoise' badge — Desert 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. What does SET score TO 0 do in an algorithm?
A. It prints the word score on the screen
B. It stores the value 0 in a variable called score ✓
SET gives a variable a value. Here the variable score starts at 0.
2. Which one is a variable name?
A. lives ✓
B. TO
A variable is a named place that holds a value. 'lives' is a name we choose. TO is part of the SET instruction.
3. Which step makes a counter go up by one?
A. ADD 1 to score ✓
B. SET score TO score
ADD 1 to score changes the stored value so it is one bigger each time.
4. score is 0. After SET score TO 5, what is score?
A. 5 ✓
B. 0
SET replaces the old value. The variable now stores 5.
5. A variable can only ever hold one value and can never change.
A. True: it is fixed once it is made
B. False: its value can be set and changed ✓
That is why it is called a variable. Later steps can change what it stores.

Match the Pairs

SET score TO 0 → Makes a variable called score and gives it the starting value 0
ADD 1 TO score → Changes the variable score by making its stored value one bigger
A counter variable starts at zero before counting begins → SET lapCount TO 0
A variable can store a value that changes later in the algorithm → SET lives TO 3 ADD 1 TO lives
ADD 1 TO score SET score TO 0 → The steps are in the wrong order. The variable is changed before it has a starting value, so the counter would be reset to 0 and the count lost. SET should come first.
SET 0 TO score → The variable name and value are swapped. The name score should come after SET and the value 0 after TO: SET score TO 0.

Key Term

SET score TO 0
A variable is a named place that stores a value. SET gives it a value, like 0, and later steps can change it, such as ADD 1 to score, so it works as a counter.

Fill in the Blanks

1. SET score TO 0
Hint: Type the keyword that gives a variable its first value.
2. SET score TO 0
Hint: Type the small word that links the variable name to the value it stores.
3. SET score TO 0
Hint: Type the starting number for a score counter before any points are won.
4. SET score TO 0 ADD 1 TO score SHOW score
Hint: Type the name of the variable that is being changed.
5. SET count TO 0 REPEAT 3 TIMES ADD 1 TO count
Hint: Type the keyword that makes the counter go up each time the loop runs.

Spot the Error

Question 1
A SET score TO 0
B REPEAT 3 TIMES
C ADD 1 TO points
D DISPLAY score
Line C — The variable was named score, but this line adds to points, which was never set. It should be ADD 1 TO score.
Question 2
A SET lives TO 3
B SET score TO 0
C ADD 1 TO score
D DISPLAY scores
Line D — There is no variable called scores. The variable is named score, so the line should be DISPLAY score.
Question 3
A SET steps TO 0
B ADD 1 TO steps
C ADD steps TO 1
D DISPLAY steps
Line C — The words are in the wrong order. The number goes first and the variable goes last, so it should be ADD 1 TO steps.
Question 4
A SET count TO 0
B ADD 1 count
C ADD 1 TO count
D DISPLAY count
Line B — The word TO is missing. The step should be ADD 1 TO count so it is clear which variable gets the 1 added.
Question 5
A SET lives TO 3
B SUBTRACT 1 FROM lives
C SUBTRACT 1 FROM lives
D DISPLAY 3
Line D — This shows the number 3 instead of the variable. Lives has changed to 1, so the line should be DISPLAY lives.

Student with a class code? Join your class →