GCSE · Computer Science · OCR · Spec J277
Boolean operators AND, OR, NOT
A program can't say 'sort of'. Is this card a king and a heart? It must answer True or False, and three little words decide which.
Computer Science · Logical operators
and, or, not: read the rule off the rows
A and B are the results of two comparisons, like x > 3 or name == "Sam". Each one is True or False. Step through every combination and watch what each operator does with them.
Computer Science · Logical operators
A number, or True or False?
Sort each expression. Does it work out to a number, or to True or False?
Still to sort
Arithmetic expression: gives a number (0)
Maths on values, like + - * and /. The answer is a number.
Where the line is: No comparison and no and, or or not deciding the final answer: just a calculation.
Logical expression: gives True or False (0)
Comparisons such as > or == joined with and, or or not.
Where the line is: There can be maths tucked inside, but if comparisons are joined by and, or or not, what comes out is True or False.
Every expression works out to something. The question is what kind of something.
Predict, then check
Your card is the five of hearts.
For the five of hearts, what does value == "king" and suit == "hearts" give?
Computer Science · Logical operators
Which path does the program take?
The selection's condition is age > 12 and age < 60. Pick a route and follow it to the path the program takes.
Is age > 12? → Is age < 60?
Two comparisons joined by and. Their single True or False result decides the path.
3 possible routes.
A selection has more than one possible path. Here, a logical expression decides which one runs.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
What you need to know
- An arithmetic expression works out to a number. A logical expression works out to just True or False.
- Relational operators, like > and ==, compare two values inside a condition. Each comparison comes out True or False.
- The three basic logical operators are and, or and not.
- Logical operators earn their keep when you need several comparisons to give back one single True or False.
- A logical expression combines relational and logical operators to check more than one value, like age > 12 and age < 60.
- and is True only when both comparisons are True. One False makes the whole thing False.
Have a goA ride lets you on if height > 120 and height < 200. Your mate is 210 cm tall and shouts, "I'm way over 120, I'm in!" Is the expression True?
No. It's False, so your mate stays on the ground.
height > 120 is True, but height < 200 is False. and needs both, so being over 120 isn't enough on its own.
- or is True when either comparison is True, or when both are. Both False is the only way to get False.
Have a gotemperature is 30. Before you peek: is temperature < 0 or temperature > 25 True or False?
True.
temperature < 0 is False, but temperature > 25 is True. One False doesn't sink an or: only two Falses do.
- not is True when its comparison is False, and False when it's True. It flips the result.
Have a gocoins is 0. What does not (coins > 0) give?
True.
coins > 0 is False, because 0 is not more than 0. not turns that False into True, so don't just copy the comparison's answer.
- Selection is used when a program has more than one possible path to follow.
- Put a logical expression in a selection statement and its True or False result controls which path runs.
The big picture
An arithmetic expression works out to a number; a logical expression works out to True or False. A logical expression combines relational operators, which compare two values, with the three basic logical operators: and, or and not. and is True only when both comparisons are True. or is True when either or both are True. not is True when its comparison is False. Put a logical expression in a selection statement and its single True or False result decides which path the program follows.
Key points
Worked example
Problem
A quiz game reaches a selection with the condition lives > 0 and time < 60. If the expression is True, the next question appears. If it is False, the game ends. Right now lives is 2 and time is 75. What happens?
⚠ Watch out
Reading or as 'one or the other, but not both', and calling value > 7 or suit == "spades" False for the ten of spades. Two Trues still give True. The mirror slip with and: calling it True because one condition matches.
Memory hook
and is the strict bouncer: both of you, or nobody gets in. or is the easy-going one: one of you is fine, two is fine too. not is the contrarian: whatever it hears, it says the opposite.
Check yourself
Invent a card. Test it against value > 7 and suit == "spades", then value > 7 or suit == "spades". Can you find a card where they disagree, and say why?
Flashcards
(13)What does an arithmetic expression evaluate to?
What does a logical expression evaluate to?
What two kinds of operator does a logical expression combine?
What does a relational operator do in a condition?
Name the three basic logical operators.
When do you need logical operators?
When is an and expression True?
When is an or expression True?
When is an or expression False?
When is not True?
Ten of spades: value > 7 or suit == "spades". True or False?
When is selection used in a program?
How can logical operators control program flow?
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 OCR GCSE Computer Science topics
How this lesson was checked. This OCR GCSE Computer Science (specification J277)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 3 November 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.