← IGCSE Computer Science Paper 2

Combining AND, OR and NOT with brackets

Brackets are worked out first. Without them NOT is done first, then AND, then OR. So A OR B AND C means A OR (B AND C), and brackets change that order.

Understanding Combining AND, OR and NOT with brackets in IGCSE Computer Science Paper 2

What it does: A OR B is worked out inside the brackets first, then NOT reverses the result. NOT has the highest priority, so this means (NOT A) AND B. AND is done before OR, so B AND C is grouped first. Brackets are needed to make OR go first. The brackets go first: TRUE AND FALSE is FALSE. NOT FALSE is TRUE. NOT is done first and only affects A. To negate both, write NOT (A AND B). With no brackets, AND has higher priority than OR, so B AND C is evaluated first. The programmer wants HasTicket checked for both age groups, which needs brackets around the OR part.

Common mistakes: The opening bracket has no closing bracket. Brackets must come in pairs. It should be IF (A OR B) AND C THEN so that A OR B is worked out first. No age can be both under 5 and over 64, so AND is never true and nothing would be output. To match a child or a senior it must be OR: IF Age < 5 OR Age > 64 THEN.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 358–368) and word search (Modules 358–378).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Without brackets, in what order is NOT A OR B AND C worked out?
NOT first, then AND, then OROR first, then AND, then NOT
Matches
IF Age < 12 OR Age > 65 AND HasTicket
↓
AND is done before OR, so HasTicket only applies to Age > 65. Brackets are needed: (Age < 12 OR Age > 65) AND HasTicket.
Applying
Meanings
Term
(A OR B) AND C
Meaning
Brackets are worked out first. Without them NOT is done first, then AND, then OR. So A OR B AND C means A OR (B AND C), and brackets change that order.
Practice
IF (Age >= 16 OR Parent = TRUE) AND NOT Banned THEN
Testing
Gaps
IF (Age < 12 Age > 65) AND Paid THEN
Check Answer
Spots
1IF (A OR B AND C THEN
2 OUTPUT "Go"

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Lion's Mane Jellyfish' badge — Set Operator, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Without brackets, in what order is NOT A OR B AND C worked out?
A. NOT first, then AND, then OR ✓
B. OR first, then AND, then NOT
Without brackets the order is NOT, then AND, then OR. Brackets are always worked out before all of them.
2. Which condition means the same as A OR B AND C?
A. (A OR B) AND C
B. A OR (B AND C) ✓
AND is done before OR, so B AND C is grouped first. Brackets are needed to make OR go first.
3. A = TRUE, B = FALSE, C = FALSE. What is (A OR B) AND C?
A. TRUE
B. FALSE ✓
The brackets go first: TRUE OR FALSE is TRUE. Then TRUE AND FALSE is FALSE.
4. A = TRUE, B = FALSE, C = FALSE. What is A OR B AND C with no brackets?
A. TRUE ✓
B. FALSE
AND goes first: FALSE AND FALSE is FALSE. Then TRUE OR FALSE is TRUE. Moving the brackets changed the answer.
5. A = TRUE, B = FALSE. What is NOT (A AND B)?
A. TRUE ✓
B. FALSE
The brackets go first: TRUE AND FALSE is FALSE. NOT FALSE is TRUE.

Match the Pairs

A OR B AND C → Means A OR (B AND C), because AND is worked out before OR when there are no brackets
(A OR B) AND C → A OR B is worked out first, then the result must be true together with C
Brackets make NOT apply to a whole condition, so it is true only when both A and B are false → NOT (A OR B)
Without brackets, NOT is done first and only reverses the value right after it → NOT A AND B
IF Age < 12 OR Age > 65 AND HasTicket → AND is done before OR, so HasTicket only applies to Age > 65. Brackets are needed: (Age < 12 OR Age > 65) AND HasTicket.
TRUE OR FALSE AND FALSE = FALSE → The condition was worked out left to right. AND comes first: FALSE AND FALSE is FALSE, then TRUE OR FALSE is TRUE.

Key Term

(A OR B) AND C
Brackets are worked out first. Without them NOT is done first, then AND, then OR. So A OR B AND C means A OR (B AND C), and brackets change that order.

Fill in the Blanks

1. IF (Age < 12 OR Age > 65) AND Paid THEN OUTPUT "Half price" ENDIF
Hint: Type the logical operator that lets either age condition be true, since nobody is both under 12 and over 65.
2. IF NOT (Raining OR Windy) THEN OUTPUT "Play outside" ENDIF
Hint: Type the operator that reverses the result of the whole bracketed condition.
3. Result <- (TRUE OR FALSE) AND FALSE // Result is FALSE
Hint: The brackets give TRUE first. Type the operator that turns TRUE and FALSE into FALSE.
4. Result <- TRUE OR FALSE AND FALSE // AND first, so Result is TRUE
Hint: AND is worked out before this operator. Type the operator that gives TRUE overall.
5. Result <- NOT (TRUE AND FALSE) // Result is TRUE
Hint: Type the Boolean value that makes the bracket FALSE, so NOT turns it into TRUE.

Spot the Error

Question 1
A IF (A OR B AND C THEN
B OUTPUT "Go"
C ENDIF
Line A — The opening bracket has no closing bracket. Brackets must come in pairs. It should be IF (A OR B) AND C THEN so that A OR B is worked out first.
Question 2
A INPUT Age
B IF Age < 5 AND Age > 64 THEN
C OUTPUT "Child or senior"
D ENDIF
Line B — No age can be both under 5 and over 64, so AND is never true and nothing would be output. To match a child or a senior it must be OR: IF Age < 5 OR Age > 64 THEN.
Question 3
A Rain <- FALSE
B Wind <- TRUE
C IF NOT Rain OR Wind THEN
D OUTPUT "Play outside"
E ENDIF
Line C — Without brackets NOT is done first and only applies to Rain, so it is (NOT Rain) OR Wind. That is TRUE when it is windy. The brackets are needed so NOT applies to the whole of Rain OR Wind: IF NOT (Rain OR Wind) THEN.
Question 4
A A <- TRUE
B R <- (A OR FALSE) AND FALSE
C OUTPUT R
D // Output is TRUE
Line B — These brackets make OR happen first: TRUE AND FALSE gives FALSE, not the TRUE the comment expects. AND is worked out before OR, so the brackets belong round FALSE AND FALSE: R <- A OR (FALSE AND FALSE).
Question 5
A INPUT Age
B INPUT Late
C IF Age < 18 OR NOT Late THEN
D OUTPUT "Young and on time"
E ENDIF
Line C — The message says the person is young AND on time, so both parts must be true. OR would let in anyone under 18 even if they are late. It should be IF Age < 18 AND NOT Late THEN.

Student with a class code? Join your class →