GCSE · Computer Science · AQA · Spec 8525
Subtraction (arithmetic operator)
14 °C at 9 am, 9 °C by 3 pm. Did the temperature change by -5 or by 5? In code, it depends on which number you write first.
Computer Science · Algorithms
Trace table — dry run the code
A weather app stores two temperature readings and works out the change. Before each Next, predict what the line will store. Line 4 is the one to watch.
Ready when you are — step through one line at a time.
Predict, then check
Two minus signs in one line. Which subtraction happens first?
A program runs this line: left ← 20 - 5 - 3. What number is stored in left?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
The same two numbers can give a rise or a fall. It all depends on which one you write first.
What you need to know
- The subtraction operator (-) takes the second operand away from the first: a - b.
- Order matters. a - b and b - a have the same size but opposite signs, e.g. 9 - 14 = -5 and 14 - 9 = 5.
- A chain such as 20 - 5 - 3 is worked left to right (answer 12). Brackets are worked first: 20 - (5 - 3) = 18.
- The result must be stored (assigned to a variable) if the program needs it later.
- x ← x - 1 updates x: the current value is used, then the answer replaces it.
The big picture
The subtraction operator (-) takes the second value away from the first. The values either side of it are called operands, and their order matters: 9 - 14 is -5, but 14 - 9 is 5. The answer has the same size and the opposite sign. A chain like 20 - 5 - 3 is worked left to right, and brackets change that order. The result only survives if it is stored, and a line like later ← later - 2 updates a variable using its own current value.
Key points
Worked example
Problem
A car park program starts with spaces ← 150. Then these lines run in order: spaces ← spaces - 40, then spaces ← spaces - 25, then taken ← 150 - spaces. What values are stored in spaces and taken at the end?
⚠ Watch out
Writing the operands the wrong way round, e.g. earlier - later when you meant later - earlier. The answer has the right size and the wrong sign, so it's easy to miss. Decide what the answer should mean first, then choose the order.
Memory hook
First minus second, exactly as written. Swap them and the sign flips.
Check yourself
These lines run in order: a ← 10, b ← 25, a ← a - b. What does a hold now? (Answer: -15. 10 - 25 = -15, and that replaces the 10.)
Flashcards
(7)What does the subtraction operator (-) do in a program?
Does a - b give the same answer as b - a?
How is 30 - 10 - 4 worked out?
What do the brackets do in 30 - (10 - 4)?
What does score ← score - 5 do?
Why should the result of a subtraction be assigned to a variable?
What does a negative result from later - earlier tell you?
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
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.