GCSE · Computer Science · AQA · Spec 8525
Assignment
In maths, x = x + 1 is impossible. In code it's one of the commonest lines there is. Why? Because in code, = isn't a fact. It's an order.
Computer Science · Algorithms
Trace table — dry run the code
Run this little game program one line at a time. Before each click, say out loud what you think will change. Then check.
Ready when you are — step through one line at a time.
Same symbols, different jobs
Assignment or comparison?
Pick a line, then decide what it does.
Still to sort
Assignment: changes a stored value (0)
After the line runs, a variable holds something new.
Where the line is: If the line stores a result in a variable, it's an assignment, even when a comparison appears on its right-hand side.
Comparison: tests equality, gives True or False (0)
Asks a question about values. Changes nothing.
Where the line is: A comparison produces a Boolean (True or False). It only changes a variable if an assignment stores that Boolean.
The symbols look alike, so decide by what the line DOES. In these lines = assigns and == compares, as in Python and many other languages.
Predict, then check
Commit to an answer before you reveal it.
a holds 7 and b holds 2. To swap them, someone writes two lines: a = b then b = a. Looks fine? What do a and b hold afterwards?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Work out the right-hand side, then store the answer on the left
What you need to know
- Assignment stores a value in a variable, tying that value to the variable's name.
- A constant gets its value once, when it's declared, and keeps it while the program runs.
- Right-hand side first: the expression on the right is worked out using the values held right now.
- Only then is the result stored in the variable named on the left.
Have a goTry it before you look: the line price = 3 * 4 runs. What ends up stored, and in which variable?
12, stored in price.
The right-hand side is worked out first, so price gets the result 12, not the 3 or the 4 on their own.
- A new value overwrites the old one. The old value is lost unless it was saved somewhere else first.
Have a goYour mate's game runs coins = 40, then coins = 25. They're adamant they now have 65 coins. How many do they really have?
25. Sorry, mate.
The second assignment overwrites the 40 rather than adding to it; coins would only go up if the right-hand side said coins + 25.
- The right-hand side can be a literal (7), another variable's value (best = score) or an expression (total = a + b).
- It can even use the variable's own current value: count = count + 1 adds one to count.
Have a goFinish the line so that lives goes down by one: lives = ____
lives - 1
The right-hand side must use lives' current value; writing just 1 would overwrite lives with 1 instead of taking one away.
- Assignment changes a stored value. A comparison only tests whether two values are equal, giving True or False.
- Symbols vary: many languages assign with = and compare with ==, while lots of pseudo-code assigns with ← and compares with =.
- Assignments run in sequence, so what a variable holds depends on which lines have already run.
The big picture
Assignment stores a value in a variable. The right-hand side is worked out first, using the values held at that moment, and the result then replaces whatever the variable on the left held before. Lines run in order, so what a variable holds at any point depends on which assignments have already run. And assignment isn't a comparison: a comparison only tests whether two values are equal.
Key points
Worked example
Problem
Trace this program and give the final values of x and y: x = 4, y = x * 3, x = y - x, y = y + x
⚠ Watch out
Reading = in code as 'is equal to'. It makes count = count + 1 look impossible, tempts you to write total + 1 = total, and makes a = b then b = a look like a swap. Work out the right, then store on the left.
Memory hook
Right, then left: work it out, then write it in. Read = as 'becomes'.
Check yourself
Cover the page. p holds 5. The program then runs q = p, followed by p = p * 2. What do p and q hold now, and why didn't q change when p did?
Flashcards
(12)What does an assignment statement do?
In x = y + 2, which part is dealt with first?
What happens to a variable's old value when a new value is assigned?
What is a constant, and when does it get its value?
Name four kinds of thing that can appear on the right-hand side of an assignment.
count holds 9. What does count = count + 1 do?
Assignment versus comparison: what's the difference?
Why does a = b followed by b = a fail to swap two values?
How do you swap the values of a and b safely?
Why does the order of assignment lines matter?
After best = score runs, score is changed. Does best change too?
Do all languages use = for assignment?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
- Addition (arithmetic operator)
- Advantages of structured approach
- Advantages of subroutines
- AND (Boolean operator in code)
- Authentication routines
- Boolean data type
- Character data type
- Concept of a data type
- Concept of subroutines
- Constant declaration
- Convert character code to character
- Convert character to character code
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.