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 | Flips the result of one condition (true becomes false, and the other way around) | NOT GameOver is true while the game is still going |
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 | TRUE |
OR
| A | B | A OR B |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| TRUE | TRUE | TRUE |
NOT
| A | NOT A |
|---|---|
| FALSE | TRUE |
| TRUE | FALSE |
Example — A theme-park ride accepts riders who are at least 1.20 m tall and at least 10 years old. Write the condition in CIE pseudocode.
IF (Height >= 1.20) AND (Age >= 10) THEN
OUTPUT "Welcome aboard"
ELSE
OUTPUT "Sorry, you cannot ride"
ENDIF
Example — A user can log in if they enter the correct password OR they have an active password-reset token.
IF (Password = StoredPassword) OR (HasResetToken = TRUE) THEN
OUTPUT "Login successful"
ELSE
OUTPUT "Login failed"
ENDIF
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.