Variables in Programming — Year 5 Lesson Plan
National Curriculum: Computing KS2 — use sequence, selection and repetition in programs; work with variables and various forms of input and output
Overview
Pupils develop their understanding of variables as named containers that store values which can change during a program. They use variables to track scores, counts, and user input, and understand how variables interact with selection and loops to create dynamic programs in Scratch or Python.
Learning Objectives
- Explain what a variable is and give examples of when variables are useful.
- Create, set, and change variables in a program.
- Use variables with loops and selection to build programs that respond to changing data.
- Trace through a program and predict the value of a variable at each step.
Key Vocabulary
Suggested Lesson Structure
Show a simple scoreboard: every time a team scores, the number goes up. Ask: what changes? What stays the same? Introduce 'variable' — a box that holds a value. What else in daily life changes like this? (temperature readings, step counters, a bank balance).
In Scratch (or Python if class is ready): create a variable called 'score'. Set it to 0 at the start. Inside a loop, if the sprite touches a coin, increment score by 1 and play a sound. Display the score on screen. Trace through: what is the value of score at the start? After collecting 3 coins? Introduce: variables can also store text (e.g. player name) or Boolean (true/false). Show how to initialise variables correctly at the start of a program.
Pupils extend a starter game in Scratch: add a 'lives' variable starting at 3 that decreases by 1 when the sprite touches a hazard. When lives reach 0, the game ends. Trace through: what happens to the variable over time?
Pupils add a timer variable to their game: it starts at 30 and counts down. If the timer reaches 0 before the player collects 5 coins, the player loses. They must: create the variable, initialise it, update it in a loop, and use selection to check the winning/losing condition.
Trace challenge: show a short program on the board with a loop and variable. Pupils write down the value of the variable after each iteration. Discuss: what is the value at the end? Why? Connect to real programs: every app on a phone uses variables to track your data.
Common Misconceptions
- Pupils often forget to initialise variables — if a variable is not set to a starting value, it may contain unexpected data from previous runs.
- Confusing variable names with their values — the name 'score' is just a label; the actual number it holds can change.
Prior Knowledge
Pupils should already be able to:
- Confident use of sequences, loops, and selection in Scratch.
- Understanding that programs can respond to conditions.
- Some exposure to the concept of input and output in programs.
Want a personalised version of this lesson?
Use Staffroom to generate a complete lesson plan tailored to your class — add context about ability, recent learning, or specific pupils and get a plan ready to teach. Free trial, no card required.