Boolean Logic & Decision Control: Compound Conditions And Bracket Priority (Copy)
Compound Conditions And Bracket Priority (Cambridge Standard – O Level 2210 + IGCSE 0478)
Why Compound Conditions Are A Major Logic Trap In Paper 2
- Compound conditions combine:
- Two or more Boolean expressions
- Cambridge uses them to test:
- Logical reasoning
- Operator precedence
- Ability to predict real execution, not intention
- Most Paper 2 logic errors happen because:
- Students assume evaluation order
- Instead of following Cambridge precedence rules
What Cambridge Means By A Compound Condition
- A compound condition is:
- A condition made using multiple comparisons
- Joined by Boolean operators
- Uses:
- AND
- OR
- NOT
- Evaluates to:
- TRUE or FALSE
Example:
- IF age >= 18 AND age <= 65 THEN
Why Bracket Priority Matters
- Computers do not read conditions like humans
- They follow:
- Strict precedence rules
- Without brackets:
- Conditions may evaluate differently than intended
- Cambridge expects students to:
- Know default precedence
- Use brackets to control logic safely
Cambridge Boolean Operator Precedence (Must Memorise)
Cambridge applies this order:
- NOT
- AND
- OR
This applies to:
- IF conditions
- WHILE conditions
- REPEAT UNTIL conditions
Precedence Explained In Simple Terms
- NOT happens first
- AND happens before OR
- OR is evaluated last
If no brackets are present:
- This order is enforced automatically
Example Without Brackets (High-Risk)
Condition:
- IF a > 5 OR b < 3 AND c = 10 THEN
Cambridge interprets as:
- IF a > 5 OR (b < 3 AND c = 10) THEN
NOT as:
- IF (a > 5 OR b < 3) AND c = 10
Why This Causes Wrong Answers
- Students often read left-to-right
- Cambridge evaluates:
- AND before OR
- Result:
- Different branch executes
- Different output
- Lost marks
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
Using Brackets To Control Evaluation (Best Practice)
- Brackets force evaluation order
- They override default precedence
- Cambridge fully supports bracketed logic
Safe Example With Brackets
- IF (a > 5 OR b < 3) AND c = 10 THEN
Now evaluation is:
- Evaluate (a > 5 OR b < 3) first
- Then AND with c = 10
Examiner Expectation
- If logic is complex:
- Brackets should be used
- Brackets:
- Increase clarity
- Reduce ambiguity
- Prevent misinterpretation
Compound Conditions With AND Only
Example
- IF score >= 0 AND score <= 100 AND passed = TRUE THEN
Evaluation:
- All three conditions must be TRUE
Examiner Focus
- AND chains are:
- Common
- Usually safe
- Still evaluated left-to-right, but:
- All must be TRUE regardless of order
Compound Conditions With OR Only
Example
- IF option = 1 OR option = 2 OR option = 3 THEN
Evaluation:
- TRUE if any one comparison is TRUE
Common Student Error
Incorrect:
- IF option = 1 OR 2 OR 3 THEN
Why wrong:
- Each comparison must be explicit
- OR does not “carry over” values
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
Mixing AND And OR (Most Dangerous Case)
Example Without Brackets
- IF mark >= 80 OR mark >= 65 AND mark < 80 THEN
Cambridge interprets as:
- IF mark >= 80 OR (mark >= 65 AND mark < 80) THEN
This is actually correct for grading logic.
Same Logic Written Safely
- IF (mark >= 80) OR (mark >= 65 AND mark < 80) THEN
Examiner Insight
- Cambridge often relies on precedence
- But students are expected to:
- Understand how it works
- Or use brackets explicitly
Using NOT In Compound Conditions
Example
- IF NOT (age < 18 OR age > 65) THEN
Meaning:
- Age is between 18 and 65 inclusive
Logical Breakdown
- Inner OR evaluated first
- NOT reverses entire result
Common NOT Mistake
Incorrect:
- IF NOT age < 18 OR age > 65 THEN
Interpreted as:
- (NOT age < 18) OR age > 65
Which is:
- age >= 18 OR age > 65
- Almost always TRUE
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
De Morgan’s Laws (Implicitly Tested)
Cambridge may not name them, but tests them.
Law 1
- NOT (A AND B)
= (NOT A) OR (NOT B)
Law 2
- NOT (A OR B)
= (NOT A) AND (NOT B)
Example In Validation
Original:
- IF NOT (x >= 0 AND x <= 100) THEN
- OUTPUT “Invalid”
- ENDIF
Equivalent:
- IF x < 0 OR x > 100 THEN
Examiner Expectation
- Students should:
- Recognise equivalent logic
- Avoid unnecessary complexity
Compound Conditions In WHILE Loops
Safe Pattern
- WHILE index <= max AND NOT found DO
Evaluation:
- Loop stops if:
- index exceeds max
- OR found becomes TRUE
Dangerous Pattern
- WHILE index <= max OR NOT found DO
Why dangerous:
- NOT found alone can keep loop running forever
Compound Conditions In REPEAT UNTIL
Example
- REPEAT
- INPUT value
- UNTIL value >= 1 AND value <= 10
Stops only when:
- Both conditions are TRUE
Common Error
Using OR:
- UNTIL value >= 1 OR value <= 10
Which becomes:
- TRUE for almost all values
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
Compound Conditions With Arrays
Example
- IF marks[i] >= 50 AND marks[i] <= 100 AND present[i] = TRUE THEN
- passCount ← passCount + 1
- ENDIF
Examiner Focus
- Conditions must:
- Protect array bounds
- Apply correct filters
How Cambridge Tests Bracket Priority In Exams
- Predict-the-output questions
- Trace tables with mixed conditions
- “Explain why this condition fails”
- “Correct the logical error” tasks
How To Safely Handle Compound Conditions In Exams
- Translate condition into English
- Identify:
- Which conditions must all be TRUE
- Which are alternatives
- Apply:
- AND for “all”
- OR for “any”
- Use brackets whenever logic is mixed
Fast Exam Checklist For Compound Conditions
- Are AND and OR mixed?
- Is NOT applied to the correct part?
- Would brackets make intent clearer?
- Can the condition become FALSE/TRUE correctly?
- Does logic match English meaning?
Common Examiner-Penalised Errors
- Relying on assumed left-to-right execution
- Missing brackets with NOT
- Using OR in range checks
- Writing ambiguous compound conditions
- Conditions that are always TRUE or FALSE
Final Quality Checklist
- Correct precedence applied
- Brackets used where needed
- No ambiguous logic
- Safe termination conditions
- Clear decision control
Final Lock-In Rules
- NOT > AND > OR (memorise)
- AND restricts, OR expands
- Brackets override precedence
- Ambiguous logic loses marks
- Clear compound conditions = safe Paper 2 decisions
