Topic 3.5 Notes – Boolean Expressions
1. What Boolean Values Are
A Boolean value can only be one of two things: true or false. Nothing in between.
Programs use Boolean values to decide what to do. Whenever you see an IF statement or a loop condition, it’s checking a Boolean expression.
A Boolean expression is any expression that evaluates to either true or false.
Two big categories create Boolean values:
- Relational operators → compare values
- Logical operators → combine or modify Boolean values
If you see a condition on a quiz, your job is simple: figure out whether it becomes true or false.
2. Relational Operators Compare Two Values
Relational operators compare two variables, expressions, or values. The result is always a Boolean.
The Six You Must Know
These are exactly the ones on the AP reference sheet:
=equal to≠not equal to>greater than<less than≥greater than or equal to≤less than or equal to
Each side can be:
- A number (
7) - A variable (
score) - An expression (
x + 3)
How to Evaluate One
Example:
x ← 8
y ← 10
x + 2 ≥ y
Step-by-step thinking:
- Evaluate arithmetic first
x + 2→8 + 2→10 - Compare
10 ≥ 10 - Decide
That’s true
Two common mistakes:
- Forgetting that
=means comparison in pseudocode (assignment uses←) - Forgetting that
≥and≤include equality
Boundary cases show up a lot on multiple choice questions.
3. Logical Operators Combine or Modify Boolean Values
Logical operators work only on Boolean values or Boolean expressions. They also produce a Boolean.
The three you need:
NOTANDOR
NOT
NOT condition
It flips the value.
NOT true→ falseNOT false→ true
If you see NOT(score = 90), evaluate the inside first, then reverse it.
AND
condition1 AND condition2
True only if both conditions are true.
Think of it as a checklist. If one fails, the whole thing is false.
OR
condition1 OR condition2
True if:
- The first is true
- The second is true
- Both are true
It’s only false when both are false.
Here’s a quick truth summary you should recognize instantly:
| A | B | A AND B | A OR B |
|---|---|---|---|
| true | true | true | true |
| true | false | false | true |
| false | true | false | true |
| false | false | false | false |
And for NOT:
| A | NOT A |
|---|---|
| true | false |
| false | true |
If you ever blank during a test, rebuild the logic from this pattern.
4. Evaluating Combined Boolean Expressions
On quizzes and the AP exam, conditions are usually layered.
Example:
(a > 3) AND (b ≤ 12)
How to evaluate:
- Evaluate each relational comparison first.
Each becomes true or false. - Apply
NOTif present. - Combine using
ANDorOR.
Example:
a ← 4
b ← 15
(a > 3) AND (b ≤ 12)
a > 3→ trueb ≤ 12→ falsetrue AND false→ false
Final answer: false
Important rule from the reference sheet:
The operand of a logical operator must be:
- A Boolean value
- Or a Boolean expression
You cannot write 5 AND 7. Each side must evaluate to true or false.
Students often lose points by misreading grouped conditions. Slow down and evaluate one piece at a time.
5. Why Boolean Expressions Matter in Programs
Boolean expressions control:
- Whether an
IFstatement runs - Which branch of code executes
- Whether a loop continues
Because programs execute statements in order, changing a Boolean condition can completely change the output.
When the AP gives you a code segment and asks what prints, almost always you’re tracing Boolean conditions somewhere.