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, 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.

1CONSTANT BONUS = 5
2score = 10
3lives = 3
4score = score + BONUS
5lives = lives - 1
6best = score
7score = 0
8score = score + 1
BONUS
score
lives
best
Press Start to run the first line.
·

Ready when you are — step through one line at a time.

What does = mean?

The line that breaks maths

A program has just given count the value 4. The next line to run is: count = count + 1

Which is closest to what you think that line does?
How sure are you?

Spot the difference

Assignment or comparison?

Pick a line, then choose 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.

6 of 6 still to sort.

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. What do a and b hold afterwards?

Your turn

Write the missing assignments

This program swaps left and right safely, then works out a total and adds 1 to it. Choose each missing line.

  1. left = 7A literal: the value is written straight into the code.
  2. right = 2Next: left is about to be overwritten, so save its value in a spare variable called temp first.
  3. missing step
Which line is step 3?

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. A constant is given its value once, when it is declared, and does not change while the program runs.
  • Right-hand side first: the expression on the right is worked out using the values held now, then the result is stored in the variable on the left.
  • Assigning a new value overwrites the old one. The old value is lost unless it was stored somewhere else first.
  • The right-hand side can be a literal (7), another variable's value (best = score), an expression (total = a + b) or the variable's own current value (count = count + 1).
  • Assignment changes a stored value; a comparison tests whether two values are equal and gives True or False. Many languages write these as = and ==; lots of pseudo-code uses ← to assign and = to compare.
  • Assignments run in sequence, so the value a variable holds depends on the order of the lines that 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. Because lines run in order, what a variable holds at any point depends on which assignments have already run. Assignment is different from a comparison, which only tests whether two values are equal.

Key points

1Evaluate the right, then store on the left.
2A variable holds one value at a time; a new assignment replaces it.
3Save a value in a temporary variable before overwriting it if you still need it.
4Change the order of the lines and you can change the result.
5Assigning stores a value; comparing only asks a True-or-False question.

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?
It stores a value in a variable, replacing whatever the variable held before.
In x = y + 2, which part is dealt with first?
The right-hand side. y + 2 is worked out using y's current value, and then the result is stored in x.
What happens to a variable's old value when a new value is assigned?
It is overwritten and lost, unless it was stored somewhere else first.
What is a constant, and when does it get its value?
A named value that does not change while the program runs. It is given its value once, when it is declared.
Name four kinds of thing that can appear on the right-hand side of an assignment.
A literal, another variable's value, an expression, or the variable's own current value.
count holds 9. What does count = count + 1 do?
It works out 9 + 1 = 10, then stores 10 in count, replacing the 9.
Assignment versus comparison: what's the difference?
Assignment changes the value stored in a variable. A comparison tests whether two values are equal and gives a Boolean (True or False), changing nothing.
Why does a = b followed by b = a fail to swap two values?
The first line overwrites a with b's value, so a's original value is gone before the second line runs. Both end up holding b's original value.
How do you swap the values of a and b safely?
Save one first in a temporary variable: temp = a, then a = b, then b = temp.
Why does the order of assignment lines matter?
They run one after another, so each line works with the values left behind by the lines before it.
After best = score runs, score is changed. Does best change too?
No. best was given the value score held at that moment. Nothing links the two variables afterwards.
Do all languages use = for assignment?
No. Many languages assign with = and compare with ==, while lots of pseudo-code assigns with ← and compares with =. The operation is the same whatever the symbol.

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 posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

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 September 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.