Pilot · L03 · 50 minutes
Decisions and Boolean reasoning
Evaluate compound Boolean conditions, trace IF, IF ELSE and nested conditionals, and test a club eligibility checker at its boundaries to expose an OR that should be AND.
Topics: 3.5 Boolean Expressions · 3.6 Conditionals · 3.7 Nested Conditionals
Goals and vocabulary
By the end you can:
- Translate a written rule into a correct relational and Boolean condition.
- Evaluate AND, OR and NOT, and find an input where AND and OR give different results.
- Trace which branch runs for a given input, including at a boundary value.
- Explain why two independent IF statements can both run while IF ELSE runs exactly one block.
- Trace a nested conditional by following only the branches actually taken.
- Boolean value
- A value that is either true or false.
- Relational operator
- An operator that compares two values and produces a Boolean, such as ≥ or ≠.
- Logical operator
- AND, OR or NOT, which combine or flip Boolean values.
- Conditional statement
- A statement that runs a block only when a condition is true (IF), optionally with an alternative (ELSE).
- Boundary value
- An input exactly at, or just either side of, the point where a rule changes its answer.
- Nested conditional
- A conditional statement placed inside a branch of another conditional.
Boolean values and relational operators
A Boolean value is either true or false. Relational operators compare two values and produce a Boolean: =, ≠, >, <, ≥ and ≤ in AP pseudocode (==, !=, >, <, >=, <= in Python).
Our running example is a club eligibility checker. The rule from the club is: a student may join if they are at least 14 and the club has more than 0 places. “At least 14” means age ≥ 14, so 14 itself is allowed. “More than 0” means places > 0, so 0 is not.
AND, OR and NOT
a AND b is true only when both are true. a OR b is true when at least one is true (including when both are). NOT a flips a single value.
| old | room | old AND room | old OR room | NOT (old AND room) |
|---|---|---|---|---|
| true | true | true | true | false |
| true | false | false | true | true |
| false | true | false | true | true |
| false | false | false | false | true |
AND and OR agree on the first and last rows and disagree on the middle two. Those middle rows are exactly the inputs that reveal which operator a program uses.
NOT (old AND room) means “not both”. It is the same as (NOT old) OR (NOT room). It is not the same as (NOT old) AND (NOT room), which means “neither”.
IF and IF ELSE
IF ((age ≥ 14) AND (places > 0)){ DISPLAY("You can join")}ELSE{ DISPLAY("Not eligible")}The condition is evaluated once. If it is true, only the first block runs; otherwise only the ELSE block runs. Exactly one of the two messages is displayed.
Two separate IF statements are different: each condition is checked on its own, so both blocks can run, or neither.
| Structure | Code | Displays |
|---|---|---|
| Two independent IFs | IF (score ≥ 50) { DISPLAY("Pass") } IF (score ≥ 80) { DISPLAY("Merit") } | Pass Merit |
| IF ELSE | IF (score ≥ 80) { DISPLAY("Merit") } ELSE { DISPLAY("Pass") } | Merit |
Worked example: testing the checker at the boundary
Worked example
A student wrote this checker. Predict what it displays for a 14-year-old when the club has 1 place.
IF ((age > 14) OR (places > 0)){ DISPLAY("You can join")}ELSE{ DISPLAY("Not eligible")}| age, places | Rule says | Buggy checker | Why |
|---|---|---|---|
| 14, 1 | join | join | age > 14 is false, but places > 0 is true and OR needs only one. |
| 13, 2 | not eligible | join | OR lets a too-young student in. This test exposes the OR bug. |
| 14, 0 | not eligible | not eligible | Both parts false. Agrees by luck. |
| 15, 0 | not eligible | join | Also exposes OR. |
Fix 1: replace OR with AND. Re-test (14, 1): now age > 14 is false, so the fixed-OR version wrongly says not eligible. Fix 2: replace > with ≥ for age. The repaired condition is (age ≥ 14) AND (places > 0), and it gives the rule’s answer for all four tests.
Nested conditionals
A conditional can sit inside another. The inner condition is only checked when the outer branch containing it runs.
IF (member){ IF (places > 0) { DISPLAY("Booked") } ELSE { DISPLAY("Waitlist") }}ELSE{ DISPLAY("Join the club first")}For a non-member, the places check never happens and “Join the club first” is displayed, even if places is 10. To trace a nested conditional, follow the outer condition first, then only the inner block on the path you took.
Explore each concept
Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.
- All six relational operators
- AND, OR and NOT
- De Morgan equivalence and assignment
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- a (0–100)14Waiting
- b (0–100)14Waiting
- ExplorerelationsWaiting
Ready to explore: Relations, truth tables and NOT
Why: Change an input, predict the first effect, then advance one step.
Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.
Step through and experiment
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Input 114Waiting
- Input 20Waiting
Ready to experiment
Why: Predict the first change, then advance one step.
Try this: Compare ages 13 and 14 with places 0 and 1.
Step through and experiment
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Input 1yesWaiting
- Input 2noWaiting
Ready to experiment
Why: Predict the first change, then advance one step.
Try this: Try all four yes/no combinations. These fictional labels are not accessibility guarantees.
Common misconceptions
AND and OR are interchangeable
The belief: Both join two conditions, so either works.
What is actually true: They differ exactly when one part is true and the other false. Test those inputs to see which one the program uses.
Check yourself: Can you give an input where your condition is true with OR but false with AND?
Only one IF can run
The belief: Two IF statements in a row work like IF ELSE.
What is actually true: Independent IF statements each check their own condition, so both can run. Only IF ELSE guarantees exactly one block.
Check yourself: Pick an input that makes both conditions true. What is displayed?
One passing test proves the condition
The belief: It worked for my test, so the checker is correct.
What is actually true: A wrong condition often passes some tests. Test on and either side of each boundary and where the parts disagree.
Check yourself: Which of your tests would fail if ≥ were changed to >?
Guided practice
Guided: complete the truth table and test the checker
With a partner, complete a truth table for the repaired rule, then test the buggy checker from the worked example with your own inputs.
(age ≥ 14) AND (places > 0)- Write the four rows of the truth table for (age ≥ 14) and (places > 0) and the AND result.
- Choose one concrete (age, places) pair for each row, using boundary values where you can.
- Run each pair through the buggy checker and the repaired condition by hand and record both results.
- Circle the pairs where the two disagree and explain which bug each one exposes.
Independent practice
Independent: two structures that disagree
A library shows messages about overdue books. Compare the two versions.
IF (days > 7){ DISPLAY("Overdue")}IF (days > 28){ DISPLAY("Fine due")}IF (days > 28){ DISPLAY("Fine due")}ELSE{ IF (days > 7) { DISPLAY("Overdue") }}- Trace both versions for days = 3, 7, 8, 28 and 30.
- Give an input for which the two versions display different things, and state both outputs.
- Explain the difference using the words “independent” and “nested”.
- The library wants “Overdue” and “Fine due” both shown after 28 days. Which version does that?
Exit check
- Give an input (age, places) for which (age ≥ 14) OR (places > 0) and (age ≥ 14) AND (places > 0) give different results.
- Write a condition for “at most 30 students and at least 1 teacher”, using students and teachers.
Check yourself
Practice only: answers are checked in your browser and nothing is saved or sent to your teacher. Each explanation links back to the section it practises.
Lesson practice
Your practice so far
Check an answer to see its rationale.
Apply it somewhere new
Your practice so far
Check an answer to see its rationale.