GCSE · Computer Science · AQA · Spec 8525
OR (Boolean operator in code)
"Tea or coffee?" Say "both" and people look at you funny. Code is more generous. In code, OR is happy with either one, and it's happy with both.
Computer Science · Algorithms
Trace table — dry run the code
A menu only accepts 1, 2 or 3. The user types 0, then 7, then 2. Before each step, guess what the whole OR will be, then watch each part get checked.
Ready when you are — step through one line at a time.
Predict, then check
Same values. Same operators. Only the brackets have moved.
weekend ← True, holiday ← False, raining ← False. Which of these is True: (1) (weekend OR holiday) AND raining, or (2) weekend OR (holiday AND raining)?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
…and two Trues still count.
What you need to know
- OR joins two conditions into one bigger condition, and the result is always just True or False.
- A OR B is True when A is True, when B is True, or when both are True.
- The only way to get False is for A and B to be False together.
- Careful: everyday 'or' often means one but not both. Code OR happily includes both.
Have a goYour friend insists IF hungry OR bored THEN OUTPUT "Snack time" stays silent on a day they're hungry AND bored. Snack or no snack?
Snack time. The message is output.
Both parts True still makes OR True. Your friend is using everyday 'one but not both', which code OR doesn't follow.
- In an IF statement, the THEN branch runs whenever the OR condition is True.
- In a WHILE loop, the loop repeats while the OR is True, so it stops only when every part is False.
Have a goA game runs WHILE lives > 0 OR shield = True. Lives drop to 0, but shield is still True. Does the loop go round again?
Yes, it repeats.
shield = True keeps the OR True. Losing the last life only makes one part False, and the loop needs both parts False to stop.
- Write each side as a full comparison: choice = 1 OR choice = 2, never choice = 1 OR 2.
Have a goWhat's wrong with IF colour = "red" OR "blue" THEN? Rewrite it so it does what the programmer meant.
IF colour = "red" OR colour = "blue" THEN
The right side, "blue", isn't compared with anything, so it isn't a full condition. colour has to appear on both sides.
- Test the edge values: 10 < 10 is False, because 10 isn't less than itself.
- Mixing OR with AND or NOT? Brackets decide which parts are combined first, and moving them can change the answer.
- NOT (A OR B) works out the bracket first, then flips it, so it's True only when A and B are both False.
The big picture
OR joins two conditions into one that is True if at least one part is True, and that includes when both parts are True. It is False only when both parts are False. You'll use it to steer IF statements and WHILE loops, and when you mix it with AND or NOT, brackets decide which parts go together.
Key points
Worked example
Problem
A game keeps running until the player has 0 lives or the timer goes over 60 seconds. Write the WHILE condition that keeps the game going, then check what happens when lives = 2 and time = 61.
⚠ Watch out
Writing choice = 1 OR 2. It reads fine in English, but the 2 isn't compared with anything, so it doesn't test what you meant. Each side of OR needs to be a complete condition that is True or False on its own: choice = 1 OR choice = 2.
Memory hook
OR is generous: one True is enough, and two Trues are fine. The only way to fail an OR is to fail both parts.
Check yourself
If x ← 7, is x < 5 OR x > 5 True? And if x ← 5? (7: True, since 7 > 5. 5: False, since both parts fail.)
Flashcards
(7)Name the three ways A OR B can come out True.
What is the one way A OR B can come out False?
How is 'or' in code different from 'or' in everyday speech?
How long does WHILE a OR b keep looping?
What is wrong with IF answer = "y" OR "Y"?
How do you work out NOT (a OR b)?
Why do brackets matter in (a OR b) AND c?
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 26 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.