=, ≠, >, <, ≥, ≤ and NOT, AND, OR — with correct precedenceIF / ELSE blocks, including what happens when the condition is false and there's no ELSENOT (x > 5) ⟺ x ≤ 5)A theme park's ride rule: riders must be at least 48 inches tall AND at least 8 years old. Four kids at the gate:
| Kid | Height | Age | Rides? |
|---|---|---|---|
| P | 50 | 9 | ? |
| Q | 50 | 7 | ? |
| R | 45 | 10 | ? |
| S | 45 | 6 | ? |
With AND, both conditions must hold: P rides; Q, R, S don't — failing one requirement is failing.
Now the gift shop's discount: customers get 10% off if they have a coupon OR it's their birthday. One is enough; both is also fine.
You already reason with AND/OR flawlessly in daily life. The exam's only trick is making you do it precisely — in code, with NOTs mixed in, three layers deep. Let's build the precision.
A Boolean value is true or false — nothing else. Relational operators compare values and produce Booleans:
a = b (equals) · a ≠ b (not equals) · a > b · a < b · a ≥ b · a ≤ b
So 7 ≥ 7 → true (≥ includes equality), 3 ≠ 3 → false. These feed directly into...
NOT a — flips: true becomes false, false becomes true.a AND b — true only when both are true.a OR b — true when at least one is true. Inclusive: true OR true → true. (Not "one or the other but not both" — everyday "or" sometimes means that; Boolean OR never does.)| a | b | a AND b | a OR b | NOT a |
|---|---|---|---|---|
| T | T | T | T | F |
| T | F | F | T | F |
| F | T | F | T | T |
| F | F | F | F | T |
Memory hooks: AND is true on exactly one row (both true); OR is false on exactly one row (both false).
Evaluation order: parentheses → relational operators → NOT → AND → OR. When in doubt, the exam almost always parenthesizes for you; when it doesn't, NOT binds tightest: NOT a AND b means (NOT a) AND b.
With x ← 10, y ← 3, evaluate NOT (x < 5) AND (y = 3 OR x = 5):
x < 5 → false
NOT false → true
y = 3 → true
x = 5 → false
true OR false → true
true AND true → TRUE
Inside-out, one operator at a time, writing each intermediate value. This is the trace-table discipline (Lesson 7) applied to logic.
IF (condition)
{
<do this when condition is true>
}
ELSE
{
<do this when condition is false>
}
Rules: exactly one branch runs — never both, never neither (when ELSE exists). Without an ELSE, a false condition means the block is skipped and execution continues after it. Code after the whole IF/ELSE runs regardless.
score ← 85
IF (score ≥ 90)
{
grade ← "A"
}
ELSE
{
grade ← "B"
}
DISPLAY (grade) → B (85 ≥ 90 is false → ELSE branch)
Two Boolean expressions are equivalent if they produce the same value for every input. The equivalences worth knowing cold:
| Expression | Equivalent | Why |
|---|---|---|
NOT (x > 5) |
x ≤ 5 |
Flipping > gives ≤ (the boundary switches sides!) |
NOT (x = y) |
x ≠ y |
Direct opposite |
NOT (a AND b) |
(NOT a) OR (NOT b) |
De Morgan: NOT distributes, AND↔OR flip |
NOT (a OR b) |
(NOT a) AND (NOT b) |
De Morgan, other direction |
The >→≤ flip is the money detail: NOT of "greater than" includes equality. NOT (x > 5) is true when x is exactly 5. Choosing x < 5 as the equivalent is the planted error.
Universal fallback: when unsure whether two expressions are equivalent, test values — especially the boundary value. One input where they differ = not equivalent.
The pieces from Lessons 7–8 now combine, exactly as exam items do:
nums ← [12, 7, 20, 3]
IF (nums[2] MOD 2 = 1)
{
DISPLAY ("odd")
}
ELSE
{
DISPLAY ("even")
}
nums[2] = 7 (1-indexed!); 7 MOD 2 = 1 → true → displays odd.
Problem: With a ← true, b ← false, evaluate: (i) a AND b (ii) a OR b (iii) NOT b (iv) NOT a OR b
Solution: (i) false (AND needs both). (ii) true (OR needs one). (iii) true. (iv) NOT binds first: (NOT a) OR b = false OR false = false.
Interpretation: (iv) is the precedence check — students who read it as NOT (a OR b) also get false here, but for the wrong reason; the exam will separate those readings with different values.
Problem: What is displayed?
x ← 4
y ← 9
IF (x > 3 AND y MOD 3 = 0)
{
x ← x + y
}
ELSE
{
y ← y − x
}
DISPLAY (x + y)
Solution: Condition: 4 > 3 → true; 9 MOD 3 = 0 → true; true AND true → true → run the IF branch: x ← 4 + 9 = 13. (ELSE skipped.) Display 13 + 9 = 22.
Interpretation: The distractor 9 (= 4 + 5) comes from running the ELSE branch too. One branch. Only one.
Problem: A program contains IF (NOT (age ≥ 13)). For which ages does the IF branch run?
Solution: NOT (age ≥ 13) is true when age ≥ 13 is false — i.e., when age < 13 (12 and under). Note the flip: NOT of ≥ is <, equality jumping to the other side. Age exactly 13 → 13 ≥ 13 true → NOT false → branch skipped.
Interpretation: Test the boundary (13): it's the entire question. NOT(≥) = <, NOT(>) = ≤, NOT(<) = ≥, NOT(≤) = >.
Problem: Which is equivalent to NOT (raining AND cold)?
(A) NOT raining AND NOT cold
(B) NOT raining OR NOT cold
(C) raining OR cold
(D) NOT raining AND cold
Solution: (B) — De Morgan: NOT over AND becomes OR of NOTs. Verify with raining = true, cold = false: original = NOT(true AND false) = NOT false = true. (A): false AND true = false ✗. (B): false OR true = true ✓. One test case eliminated (A); check another case if two choices survive.
Interpretation: "Not both" (the original) means "at least one is missing" (B). (A) says "neither" — stronger, different. English intuition backs up the algebra here; use both.
NOT (x > 5) ⟺ x ≤ 5, NOT x < 5. The boundary value (x = 5) always exposes it — test it.p ← false, q ← true, what is p OR NOT q?1. (B). NOT first: NOT q = false. Then false OR false = false. (C): Booleans aren't numbers on this exam.
n = 10?2. (C). 10 ≥ 10 true (inclusive) AND 10 MOD 2 = 0 true → true. (A) strict > fails at equality. (B) = "n > 10" in disguise (NOT-flip) — false. (D): both halves false.
What is displayed?
temp ← 65
IF (temp ≥ 70)
{
DISPLAY ("warm")
}
DISPLAY ("done")
3. (B). 65 ≥ 70 false, no ELSE → skip the block; the DISPLAY after the IF runs regardless → done. (D) forgets post-IF code runs; (A) runs a skipped branch.
NOT (score < 60)?4. (B). NOT of < is ≥ — equality flips sides. (A) > 60 wrongly excludes exactly-60: test score = 60 → original: NOT(false) = true; (A): false. Differ → not equivalent.
5. (C). Check each against height ≥ 48 AND (age ≥ 8 OR withAdult). (C): 48 ✓ ("at least 48" is inclusive) AND (age 8 ✓) → rides. (A): height 50 ✓ but age 6 ✗ and alone ✗ → the OR fails. (B): height 45 fails the AND's first requirement — the adult can't rescue a failed height check. (D): 47 fails height. Two traps in one problem: inclusive boundaries and AND's veto power.
NOT (a OR b)?6. (B). De Morgan: NOT(a OR b) = NOT a AND NOT b — "neither one." (A) flips the operator but is the equivalent of NOT(a AND b) — the other De Morgan.
What is displayed?
L ← [5, 12, 8]
IF (L[1] > L[3])
{
DISPLAY (L[2])
}
ELSE
{
DISPLAY (L[3])
}
7. (C). L[1] = 5, L[3] = 8; 5 > 8 false → ELSE → display L[3] = 8. (B) is the IF branch; (A) misindexes; (D) invents concatenation.
x > 4 AND x < 10 and x ≥ 5 AND x ≤ 9 equivalent — assuming x is an integer?8. (A). For integers, x > 4 ⟺ x ≥ 5 and x < 10 ⟺ x ≤ 9 — the ranges coincide exactly (5..9 both ways). (D) is a red herring: the question stipulates integers. This "integer-equivalence" move appears on real forms.
a ← 6, b ← 2, evaluate NOT (a MOD b = 0) OR a < b:9. (B). 6 MOD 2 = 0 → true; NOT true → false. 6 < 2 → false. false OR false = false.
10. (A) and (C). (A): a or its negation — always true (one of them must be). (C): either both are true (first clause) or at least one is false (covered by a NOT clause) — every case lands somewhere; test all four rows if unconvinced. (B) is always FALSE; (D) fails when both false.
11. (A). Inclusive bounds need ≥ and ≤ joined by AND. (B) excludes 8 and 16. (C): OR makes it always true (every number satisfies at least one side). (D): tempting De Morgan bait, but NOT(len<8 AND len>16) — the inner AND is never true (can't be both), so the NOT is always true. The correct De Morgan form would be NOT (len < 8 OR len > 16).
What is displayed?
x ← 3
IF (x MOD 2 = 0)
{
x ← x * 10
}
ELSE
{
x ← x + 10
}
IF (x > 12)
{
x ← x − 1
}
DISPLAY (x)
12. (C). First IF: 3 MOD 2 = 1 ≠ 0 → ELSE → x = 13. Second IF: 13 > 12 → x = 12. Display 12. (B) stops after the first conditional — both conditionals run in sequence; they're separate statements, not IF/ELSE partners.
Answer letter distribution check: B, C, B, B, C, B, C, A, B, A+C, A, C — singles: A×2, B×5, C×5, D×0 + multi (A,C). D absent this lesson (flagged); L10's robot answers will carry D weight. Note: problem 5's key discussion shows the verification process concluding (C) — key letter is (C).
Selection is a hard requirement of your Create PT procedure — the rubric demands a student-developed procedure containing sequencing, selection (an IF), and iteration. This lesson is the selection half.
Design guidance: the strongest PT selections decide something meaningful about the data — IF (score > highest), IF (item = searchTerm), IF (LENGTH(entry) = 0) — not decorative conditions bolted on to satisfy the rubric. Scorers (and Written Response 2(a), Algorithm Development) reward conditions you can explain the purpose of in one sentence.
Mini practice (WR 2(a) style): "Explain how the selection statement in your procedure affects your program's behavior." Model, for a high-score finder: My procedure compares each score in the list to the variable highest; the IF statement IF (scores[i] > highest) updates highest only when the current score exceeds it, so after the loop, highest holds the maximum — without the selection, every score would overwrite highest and the program would just report the last score.
1. (B). NOT first: NOT q = false. Then false OR false = false. (C): Booleans aren't numbers on this exam.
2. (C). 10 ≥ 10 true (inclusive) AND 10 MOD 2 = 0 true → true. (A) strict > fails at equality. (B) = "n > 10" in disguise (NOT-flip) — false. (D): both halves false.
3. (B). 65 ≥ 70 false, no ELSE → skip the block; the DISPLAY after the IF runs regardless → done. (D) forgets post-IF code runs; (A) runs a skipped branch.
4. (B). NOT of < is ≥ — equality flips sides. (A) > 60 wrongly excludes exactly-60: test score = 60 → original: NOT(false) = true; (A): false. Differ → not equivalent.
5. (C). Check each against height ≥ 48 AND (age ≥ 8 OR withAdult). (C): 48 ✓ ("at least 48" is inclusive) AND (age 8 ✓) → rides. (A): height 50 ✓ but age 6 ✗ and alone ✗ → the OR fails. (B): height 45 fails the AND's first requirement — the adult can't rescue a failed height check. (D): 47 fails height. Two traps in one problem: inclusive boundaries and AND's veto power.
6. (B). De Morgan: NOT(a OR b) = NOT a AND NOT b — "neither one." (A) flips the operator but is the equivalent of NOT(a AND b) — the other De Morgan.
7. (C). L[1] = 5, L[3] = 8; 5 > 8 false → ELSE → display L[3] = 8. (B) is the IF branch; (A) misindexes; (D) invents concatenation.
8. (A). For integers, x > 4 ⟺ x ≥ 5 and x < 10 ⟺ x ≤ 9 — the ranges coincide exactly (5..9 both ways). (D) is a red herring: the question stipulates integers. This "integer-equivalence" move appears on real forms.
9. (B). 6 MOD 2 = 0 → true; NOT true → false. 6 < 2 → false. false OR false = false.
10. (A) and (C). (A): a or its negation — always true (one of them must be). (C): either both are true (first clause) or at least one is false (covered by a NOT clause) — every case lands somewhere; test all four rows if unconvinced. (B) is always FALSE; (D) fails when both false.
11. (A). Inclusive bounds need ≥ and ≤ joined by AND. (B) excludes 8 and 16. (C): OR makes it always true (every number satisfies at least one side). (D): tempting De Morgan bait, but NOT(len<8 AND len>16) — the inner AND is never true (can't be both), so the NOT is always true. The correct De Morgan form would be NOT (len < 8 OR len > 16).
12. (C). First IF: 3 MOD 2 = 1 ≠ 0 → ELSE → x = 13. Second IF: 13 > 12 → x = 12. Display 12. (B) stops after the first conditional — both conditionals run in sequence; they're separate statements, not IF/ELSE partners.
Answer letter distribution check: B, C, B, B, C, B, C, A, B, A+C, A, C — singles: A×2, B×5, C×5, D×0 + multi (A,C). D absent this lesson (flagged); L10's robot answers will carry D weight. Note: problem 5's key discussion shows the verification process concluding (C) — key letter is (C).
Exam tip: For any NOT-heavy expression, don't philosophize — build a two-second truth check: pick the boundary value or one concrete true/false pair, evaluate both expressions, compare. On equivalence questions, a single well-chosen test value (usually the boundary) eliminates two or three choices instantly.