Boolean Logic & Decision Control: Boolean Operators (AND, OR, NOT) In Conditions (Copy)
Boolean Operators (AND, OR, NOT) In Conditions (Cambridge Standard – O Level 2210 + IGCSE 0478)
Why Boolean Logic Is Central To Decision Control In Paper 2
- Boolean operators control:
- Whether a condition is TRUE or FALSE
- Which branch of an IF executes
- Whether loops continue or terminate
- Cambridge heavily tests Boolean logic in:
- IF, ELSE IF, ELSE statements
- WHILE and REPEAT UNTIL conditions
- Pre-release material decision-making
- Error detection and correction questions
- Most logical errors in Paper 2:
- Are caused by incorrect Boolean reasoning, not syntax
What Cambridge Means By Boolean Logic
- Boolean logic operates on:
- Conditions that evaluate to TRUE or FALSE
- Boolean operators are used to:
- Combine conditions
- Reverse conditions
- Cambridge pseudocode uses:
- AND
- OR
- NOT
- These are:
- Written in words (not symbols like &&, ||, !)
Boolean Data Type (Foundation)
- A Boolean variable can hold only:
- TRUE
- FALSE
Examples:
- found ← FALSE
- valid ← TRUE
Boolean Operators Overview
| Operator | Purpose | Effect |
|---|---|---|
| AND | All conditions must be TRUE | Restrictive |
| OR | At least one condition must be TRUE | Permissive |
| NOT | Reverses a condition | Negation |
AND Operator (Most Common In Exams)
Meaning Of AND
- Condition1 AND Condition2 is TRUE only if:
- Condition1 is TRUE
- AND Condition2 is TRUE
If either is FALSE:
- Entire condition is FALSE
Truth Table For AND
| Condition A | Condition B | A AND B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| FALSE | FALSE | FALSE |
Example: Valid Range Check
- IF mark >= 0 AND mark <= 100 THEN
- OUTPUT “Valid”
- ENDIF
Explanation:
- mark must satisfy both conditions
Examiner Focus
- AND is used when:
- All rules must be satisfied simultaneously
- Very common in:
- Validation
- Boundary checks
- Search termination logic
Common AND Mistake
Incorrect:
- IF mark >= 0 OR mark <= 100 THEN
Why wrong:
- Almost all numbers satisfy at least one condition
- Invalid values slip through
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
OR Operator (High-Risk If Misused)
Meaning Of OR
- Condition1 OR Condition2 is TRUE if:
- At least one condition is TRUE
Only FALSE if:
- Both conditions are FALSE
Truth Table For OR
| Condition A | Condition B | A OR B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
Example: Alternative Acceptance
- IF grade = “A” OR grade = “B” THEN
- OUTPUT “Eligible”
- ENDIF
Explanation:
- Either grade is acceptable
Examiner Focus
- OR is used when:
- Multiple alternatives are allowed
- Common in:
- Menu selection
- Choice-based decisions
Common OR Mistake (Critical)
Incorrect:
- IF score < 0 OR score > 100 THEN
- OUTPUT “Invalid”
- ENDIF
This is actually correct.
But students confuse it with:
Incorrect version:
- IF score < 0 AND score > 100 THEN
Why wrong:
- No value can be both < 0 AND > 100
- Condition is always FALSE
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
NOT Operator (Logical Reversal Trap)
Meaning Of NOT
- NOT reverses a Boolean condition
- NOT TRUE → FALSE
- NOT FALSE → TRUE
Example: Negating A Flag
- IF NOT found THEN
- OUTPUT “Not Found Yet”
- ENDIF
Equivalent to:
- IF found = FALSE THEN
Truth Table For NOT
| Condition | NOT Condition |
|---|---|
| TRUE | FALSE |
| FALSE | TRUE |
Examiner Focus
- NOT is often used with:
- Boolean variables
- Flags
- Rarely used with:
- Complex arithmetic expressions (students misuse it)
Common NOT Mistakes
- Applying NOT to part of a condition unintentionally
- Forgetting what exactly is being negated
Example confusion:
- NOT a > 5
vs - NOT (a > 5)
Cambridge interprets:
- NOT (a > 5)
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Combining Boolean Operators In One Condition
Example: Search Loop Condition
- WHILE index <= max AND NOT found DO
- PROCESS
- ENDWHILE
Meaning:
- Loop continues only while:
- index is within bounds
- AND target has not been found
Examiner Expectation
- AND used to:
- Prevent out-of-range access
- NOT used to:
- Control termination
Operator Precedence (Conceptual, Not Symbolic)
Cambridge expects you to understand that:
- NOT is evaluated first
- AND is evaluated before OR
- OR is evaluated last
Example
- IF a > 5 OR b < 3 AND c = 10 THEN
Interpreted as:
- IF a > 5 OR (b < 3 AND c = 10) THEN
Not:
- (a > 5 OR b < 3) AND c = 10
Best Practice (Exam-Safe)
- Break complex conditions into:
- Nested IFs
- OR use parentheses conceptually
Boolean Logic In IF–ELSE IF Chains
Example
- IF mark >= 80 THEN
- grade ← “A”
- ELSEIF mark >= 65 AND mark < 80 THEN
- grade ← “B”
- ELSE
- grade ← “C”
- ENDIF
Examiner Focus
- Conditions must be:
- Mutually exclusive
- Boolean logic ensures:
- Only one branch executes
Boolean Logic In WHILE Loops (Termination Control)
Safe Pattern
- WHILE index <= 30 AND valid = TRUE DO
Dangerous Pattern
- WHILE index <= 30 OR valid = TRUE DO
Why dangerous:
- valid = TRUE alone keeps loop running forever
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Boolean Logic In REPEAT UNTIL (Reverse Thinking Required)
Example
- REPEAT
- INPUT value
- UNTIL value >= 0 AND value <= 100
Meaning:
- Stop only when value is valid
Common Mistake
- Using OR instead of AND
Incorrect:
- UNTIL value >= 0 OR value <= 100
This stops immediately for almost all inputs
Boolean Logic With Arrays
Example: Conditional Counting
- IF marks[i] >= 50 AND marks[i] <= 100 THEN
- count ← count + 1
- ENDIF
Examiner Focus
- AND ensures:
- Valid and passing marks only
Boolean Logic With Flags
Example
- found ← FALSE
- WHILE NOT found AND index <= n DO
- IF names[index] = target THEN
- found ← TRUE
- ENDIF
- index ← index + 1
- IF names[index] = target THEN
- ENDWHILE
Examiner Expectation
- NOT used correctly
- found updated inside loop
- Loop terminates safely
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Common Boolean Logic Errors Cambridge Penalises
- Using OR instead of AND in range checks
- Using AND instead of OR in invalid checks
- Forgetting NOT in loop conditions
- Writing conditions that are always TRUE or always FALSE
- Combining too many conditions incorrectly
Examiner Checklist For Boolean Conditions
- What must be TRUE for this to work?
- Do all conditions need to be TRUE? → AND
- Is one condition enough? → OR
- Should the logic be reversed? → NOT
- Can the condition ever become FALSE/TRUE as required?
Best-Practice Strategy For Paper 2
- Translate condition into English first
- Decide:
- “All required?” → AND
- “Any allowed?” → OR
- “Opposite meaning?” → NOT
- Keep conditions simple
- Prefer clarity over cleverness
Final Quality Checklist
- Correct operator chosen
- Condition matches intent
- No always-true / always-false logic
- Safe loop termination
- Clear decision control
Final Lock-In Rules
- AND = all must be TRUE
- OR = at least one TRUE
- NOT = reverse logic
- Boolean mistakes are logic errors, not syntax
- Correct Boolean logic = control over Paper 2 decisions
