Every decision a program makes collapses to one bit first. Flip switches through the truth tables, then watch one wrong joining word put a three-year-old on a rollercoaster.
Before a program can choose anything, the question it is asking has to collapse to a single value: true or false. Nothing in between, no maybe, no “sort of”.
Level 3 gave you the if shape. This level is about the question inside it. Real conditions are rarely one thing — they are several facts joined together, and there are exactly three ways to join them.
AND means both must hold. OR means at least one must. NOT flips it. That is the complete set. This part of the subject is called Boolean logic, after George Boole, who worked it out in the 1850s — about ninety years before anyone had a computer to run it on.
Two facts, one joining word. Change either switch and watch which row of the table you land on.
The highlighted row is the one you are standing on right now.
| A | B | result |
|---|
This is not an abstract exercise. Choosing AND where you meant OR is a real bug that ships, and it never looks wrong when you read it back. Here is a rule you have met in real life — a fairground ride.
The rule: tall enough and old enough. Now switch the joining word and watch what happens.
With OR selected, a three-year-old who happens to be tall gets on the ride, and so does a sixteen-year-old who is short. The code is not broken, the logic compiles, every test of “does it run” passes — and the rule is wrong. This is why your course description says “correct and maintainable” and not just “working”.
Look closely at height ≥ 120. Is a child of exactly 120cm allowed on? With ≥, yes. With >, no. One character, and one specific child is turned away.
Every condition you write has an edge like this, and it is almost never the middle of the range that goes wrong. It is the exact boundary. When you test your own work — the next level — the boundary is the first value you should try, not the last.
Whenever you write a comparison, immediately say out loud what happens at the exact number. “At 120 they get on.” If you cannot answer that instantly, you do not yet know what you wrote.
Write a real rule with two conditions. “Free delivery if the order is over £50 and you are a member.” “You can borrow the car if you passed your test and it is not raining.”
Find someone the rule handles badly. Someone at exactly £50. Someone who meets one half. Then ask: should that be AND, or OR?
You will find that most real rules are argued about at the boundary, not in the middle — and that plain English is genuinely ambiguous about it. “Over £50” and “£50 or more” are different rules, and a program has to pick one. Deciding which is your job, not the compiler’s.
AND, OR, NOT. Every condition you will ever read is built from those.
AND is true in one row of four. OR is true in three. Picking the wrong one is a real, shippable bug.
What happens at precisely 120? If you cannot say instantly, you do not know what you wrote.
Not recall — these are the shapes an exam actually uses. Every answer below was produced by compiling and running the code, so if you disagree with one, the compiler is the one to believe.
Have a real go before revealing. Being wrong here is worth more than being right in three weeks.
A and B are joined by AND. Out of the four possible combinations, in how many is the result true?
And with OR?
A ride needs height ≥ 120 and age ≥ 8. Someone changes it to or. Who gets on that should not?
A rule says height ≥ 120. What happens to someone who is exactly 120?
← back to all 12 levels · stuck on anything? ask peter.