Variables in a program
About this lesson

A quantity whose value can change while a program runs is a variable; one that does not change is a constant. A variable is like a labelled box: the label is the variable’s name and what is inside is its value. Every variable used in a program must be declared first. In ALPLogo you write the keyword for “variable” and then the name: variable x, variable sum1. Naming rules: Latin letters (upper and lower case), digits and the underscore (_) are allowed; the name must start with a letter; no spaces; and it must not match a command name. Correct: x, sum1, star_colour. Wrong: 1x, star colour. A value is given with the assignment sign (=): x = 60. Read it as “assign the value 60 to x” — it is not a mathematical equation! The expression on the right is worked out and the result is stored in the variable on the left, replacing the old value. For example, after a = 5 and then a = a + 2, a holds 7. If the same number appears in many places, it is handy to replace it with a variable: in a program drawing a zigzag, write “forward y, right x” instead of “forward 50, right 60”, with x = 60 and y = 50 at the top — then changing the size means editing just two lines.
What the book shows
In grade 6 the computer science textbook covers how a computer is built and works, encoding numbers, electronic presentations, the properties of algorithms and loops, variables in programs, and email. Each topic gives a short explanation, an example and a task done on or off the computer.
Textbook link:
This is not the textbook’s text but a short description of the topic. Check the exact page in your own textbook.
The lesson step by step
- 1
Warm-up5 min
Labelled boxes.
- 2
New topic10 min
Variables and constants.
- 3
Practice10 min
Declaring and naming.
- 4
Game10 min
Assignment.
- 5
Wrap-up5 min
Improving a program.
Let’s understand
For the student Simple language

| Idea | What it is | Example |
|---|---|---|
| variable | a value that can change | x, sum1 |
| declaration | announcing it first | variable x |
| assignment | right side stored on the left | x = 60 |
| new value | the old one is replaced | a = a + 2 |
For the parent
How to help
- Play a box game: label boxes x and y, put numbers on paper inside, and carry out commands like “x = x + 1” together.
For the teacher
Lesson goals
- Explain what a variable is, declare one and give it a proper name, understand the assignment sign, and make a program more efficient by replacing numbers with variables.
How to teach it
- Hands-on computer work, unplugged modelling, pair work, mini-project
Differentiation
- Weaker pupils follow the model step by step; stronger pupils design and test their own task
Questions for the class
- How can we easily change a number that appears in many places in a program?
How to check
The pupil explains variables, gives valid names, reads assignment correctly, and replaces numbers with variables in a program.
Scientific Scientific language
In maths
Maths also uses letters for unknown and changing quantities: 2x + 3.
In games
Computer games keep the score, lives and level in variables that change as you play.
Self-study
Step by step
- I explained variables.
- I chose valid names.
- I understood assignment.
- I wrote a program with variables.
Going deeper
Scientific language: for older students, parents and teachers.
In many programming languages a variable also has a type — whole number, decimal, text — which sets what values it can hold.
Play and check
Is the variable name valid?
How to write it down
- Write 5 valid and 3 invalid variable names and say why the invalid ones are wrong.
- After a = 3, b = a + 4, a = b × 2, find a and b.
- Write the square program with the side length as a variable.
How the classwork looks in the notebook
Sample: the date and heading follow this country’s notebook rules.
Watch out: common mistakes
Where it helps in life
At home
Core
- Which variables might your favourite game use? Write 4 names with sample values.
Extra ⭐
- t = 10, t = t − 3, t = t × 2 — what is t at the end?
How to do it
- Do the task with a grown-up.
- Explain in words what you noticed.
Answers for parents
a = 3; b = 3 + 4 = 7; a = 7 × 2 = 14, so a = 14, b = 7. t: 10 → 7 → 14. Square: declare s, s = 80, then 4 times “forward s, right 90”.
Step-by-step homework solution — Show the solution (try it yourself first)
Let’s improve a program
- A program has the numbers 50 and 60 in 6 places; a bigger shape would mean changing all 6. Solution: declare x and y; x = 60; y = 50; then write “right x, forward y”. Now to enlarge the shape you only write y = 100. The program is 4 lines longer but far more efficient.
How the homework looks in the notebook
Sample: the date and heading follow this country’s notebook rules.