Programming · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 13% of your exam marks.
Paper 2 is almost entirely programming. Variable types, assignments, loops and conditionals are tested every session.
Logical operators combine Boolean values and return a Boolean. The three you must know are AND, OR and NOT.
| Operator | Meaning | Result |
|---|---|---|
| AND | Result is TRUE only when every combined condition is also TRUE | (Age >= 13) AND (Age <= 18) is true only for ages in that range |
| OR | True if at least one condition is true | (Score > 90) OR (BonusActive = TRUE) is true if either holds |
| NOT |
The three operators are fully defined by their truth tables (these come up again in topics 26 and 27 on Boolean logic).
AND
| A | B | A AND B |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| TRUE | FALSE | FALSE |
| TRUE | TRUE |
OR
| A | B | A OR B |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| TRUE | TRUE |
NOT
| A | NOT A |
|---|---|
| FALSE | TRUE |
| TRUE | FALSE |
A single comparison only tests one thing. To check more than one fact at once, link comparisons with AND, OR or NOT. Each part on either side of the operator must be its own complete comparison.
AND requires both sides to be true. A common pattern is a range check built from two comparisons:
IF (Mark >= 0) AND (Mark <= 100) THEN
OUTPUT "Valid mark"
ENDIF
OR requires at least one side to be true. Useful when several different values should be treated the same way:
IF (Day = "Saturday") OR (Day = "Sunday") THEN
OUTPUT "Weekend"
ENDIF
NOT flips the result of a single comparison, so it is true when the underlying condition is false:
IF NOT (Account = "locked") THEN
OUTPUT "Login allowed"
ENDIF
Always bracket each comparison. The brackets are not strictly required by precedence, but they make the intent obvious and stop slips like writing Mark >= 0 AND <= 100, which is not valid pseudocode.
When multiple operators appear in one expression:
*, /, DIV, MOD before +, -).<, >, =, <>, <=, >=).When in doubt, use brackets generously. (A AND B) OR C is much clearer than relying on the reader to remember precedence.
| Flips the result of one condition (true becomes false, and the other way around) |
NOT GameOver is true while the game is still going |