Combining Conditions with AND, OR, and NOT
Byte the robot guide stands at a futuristic game-show control panel covered in glowing switches and dials, flipping toggles and watching colored lights flicker on and off as different combinations are tested.
- Explain what a Boolean value is and why programs use true/false conditions.
- Predict the result of AND, OR, and NOT applied to given true/false inputs.
- Identify which logical operator to use when a program must check multiple requirements at once.
- Compare how AND and OR differ when one condition is false.
- Construct a compound Boolean expression that combines two or more conditions.
Key terms
- Boolean value
- A value that is either true or false, with nothing in between
- AND operator
- Returns true only when both conditions are true
- OR operator
- Returns true when at least one condition is true
- NOT operator
- Flips a Boolean value from true to false or back
- Compound expression
- A condition that combines several smaller conditions with operators
AND and OR Are Opposites in Strictness
AND is the strict operator: it demands that every condition be true, so a single false anywhere drags the whole result to false. OR is the generous operator: it only needs one true to make the whole result true, so it stays false only when everything is false. A handy memory trick is that AND fails fast on the first false, while OR succeeds fast on the first true. Knowing which operator you are reading tells you exactly what to look for.
Evaluating Compound Expressions
When several operators appear together, evaluate the parts inside parentheses first, then apply NOT to single values, and finally combine the results with AND and OR. Replace each variable with its true or false value, simplify one operator at a time, and write down the partial result before moving on. Working in small ordered steps keeps a long expression from feeling overwhelming and prevents the common error of judging the whole thing from just one of its variables.
Worked examples
Evaluate (true OR false) AND NOT false
- Solve the parentheses first: true OR false is true because OR needs one true.
- Solve NOT false: flipping false gives true.
- Combine the results with AND: true AND true.
- AND of two trues is true.
Answer: true
Should the door open with key true and password false
- The rule is key AND password must both be true.
- Substitute the values: true AND false.
- AND requires both sides true, but one side is false.
- So the expression is false.
Answer: false, the door stays shut
Activity
Drag each Boolean expression to its correct true or false result, then build your own compound condition using the operator tiles.
Practice
Find the result of (false OR false) OR NOT true step by step.
Write a compound condition that is true only on a warm sunny day.
Common mistakes to avoid
- NOT leaves the value unchangedNOT always flips the value, turning true into false and false into true.
- One false input makes any expression falseThat is only true for AND; an OR can still be true when one input is false.
Check your understanding
A game unlocks a bonus level only if a player has more than 50 points AND has collected the hidden key. The player has 60 points but did NOT collect the key. What does the condition evaluate to?
Which expression evaluates to true?
A program checks: `(isRaining OR isCold) AND NOT isSunny`. If isRaining = false, isCold = true, and isSunny = false, what is the result?
Recap
Boolean values are either true or false. AND is true only when both sides are true, OR is true when at least one side is true, and NOT flips a value. Evaluate compound expressions in small ordered steps, starting inside parentheses.
Reflect
What everyday decision do you make using an AND or OR rule without realizing it?