Variables for kids: how to explain a variable in coding
A variable is a box with a name. How to explain variables and assignment to children, unplugged box games, common mistakes and a Looponi lesson.
Updated:

A program has to remember things: the player's name, the score, how many apples are left in the basket. Variables do the remembering. It is one of the first ideas children meet in coding, and one of the ideas they most often get slightly wrong. The simplest way to show it is with a few shoeboxes.
A variable in plain words
A variable is a box with a name. The box has a label, for example score. Inside it there is one thing: the value, for example 7.
You can do three things with the box:
- Put something in. Programmers call this assignment. We write it with an arrow:
score ← 0. - Look inside. The program checks what is in the box and uses that value, for example to print it on the screen.
- Swap the content.
score ← score + 1means: look in the box, add 1, put the result back. The old value falls out.
A box holds only one thing at a time. When you put in a new value, the old one is gone. This is the key rule, and it is worth saying many times.
Read the arrow ← as “becomes”. Many programming languages write it as =, for example score = 0 in Python. That confuses children, because in maths = means “is equal to”. The arrow shows better that the value drops into the box.
Everyday examples
- A football scoreboard. The word “Home” stays the same, the number of goals under it changes. The word is the variable's name, the number is its value.
- A step counter on a watch. Every step, the value goes up by 1.
- The thermometer outside. One name, “temperature”, with a different value in the morning and at noon.
- Today's timetable. The box “first lesson” holds maths on Monday and science on Tuesday.
- The name on a register. The teacher reads the “name” field, and each time it is somebody else.
Unplugged games
1. Labelled boxes
Take three boxes or envelopes and label them a, b and result. Write simple instructions on cards: a ← 4, b ← 3, result ← a + b. The child carries them out in order and puts number cards into the boxes. At the end they open result. Then add a ← 10 and ask whether result changed by itself. It didn't, because nobody worked it out again.
2. Swapping two cups
One cup holds juice, the other water. How do you swap them? Not without a third cup. Variables work the same way: to swap the values of a and b, you need a spare box. The child can try it with cards in envelopes.
3. The clap counter
The child holds a card that says claps with the number 0. Each time the adult claps, the child crosses out the number and writes the next one. The card shows a history of changes, but only the last number counts. That is exactly claps ← claps + 1.
4. A recipe with measures
When baking, write the recipe as variables: flour ← 2, eggs ← 3. Then the instruction “double the recipe”: flour ← flour * 2, eggs ← eggs * 2. The child works out the new values and measures the ingredients. A variable stops being abstract when it decides how many eggs go into the bowl.
5. Tracing a program on paper
Draw a table with columns x and y. Give a short program: x ← 2, y ← x + 3, x ← y * 2. The child runs it line by line and writes the current values in each row. At the end x is 10 and y is 5. This skill pays off later when hunting for bugs, as described in our guide to debugging for kids.
Common mistakes
- Mixing up the name and the value. The child expects the program to print the word “name” instead of the name somebody typed. Ask: “Do you want to show the label, or what is inside?”
- Thinking the box keeps everything. After
x ← 5andx ← 8, the box holds only 8. The 5 is gone. - Reading
x ← x + 1as an equation. In maths it makes no sense. In a program it is an instruction: work out the right side and put the result in the box on the left. - Expecting variables to update themselves. If
result ← a + bwas worked out earlier, changingalater does not changeresult. - An empty variable. The program looks into a box that nobody has filled yet. It helps to always start by giving each variable a first value.
What it looks like in Looponi
In the lesson “Ask for a name and say hello” in the First steps module, the very first hint says it plainly: a variable is a box with a name. The child places an INPUT block that asks “What's your name?” and stores the answer in the variable name. Below it they place an OUTPUT block with the label “Hello, ” and connect the blocks with pipes.
Before the run, the child predicts what the program will print when someone types “Ella”. There are three choices: “Hello, name”, “Hello, Ella” and “What's your name?” That is the first common mistake from the list above, mixing up the label and the content. Then the child watches the run and the box name: empty at first, then “Ella” drops into it. In the task the program asks two questions, name and city, so the child uses two variables.
The next lesson, “Area of a rectangle”, adds calculation: area ← a * b. The child learns that the right side of the arrow is worked out first and the result drops into the box on the left. During every run, the Variables panel next to the board shows the current value of each variable, step by step. The Code tab shows the same program in Python, where the arrow turns into =.
What age is right?
Children of 7 or 8 who read simple words can already understand a variable as a box holding a name or a score. Assignments like x ← x + 1 and tracing several variables in a table work better from about 9 or 10. What matters most is that the child sees what is in the box, not just hears about it.
Frequently asked questions
What is a variable in programming?
A named place in a program's memory that holds one value, such as a number or a name. Children find it easiest to picture as a box with a label on it.
Why is it called a variable?
Because what is inside can change while the program runs. The label on the box stays the same, but the content can be 3, then 4, then 5.
What does x ← x + 1 mean?
Take what is in box x right now, add 1, and put the result back into box x. The old value is gone and the new one stays in the box.