8.1 Arithmetic Operators
Arithmetic operators perform mathematical calculations on numeric values (INTEGER and REAL). CIE pseudocode supports six arithmetic operators — four are familiar from maths class, while MOD and DIV are specialised for integer work.
| Operator | Name | Example | Result |
|---|---|---|---|
| + | Addition | 7 + 3 | 10 |
| - | Subtraction | 7 - 3 | 4 |
| * | Multiplication | 7 * 3 | 21 |
| / | Division (REAL) | 7 / 2 | 3.5 |
| DIV | Integer Division | 7 DIV 2 | 3 |
| MOD | Modulus (Remainder) | 7 MOD 2 | 1 |
Key Distinction: / vs DIV vs MOD
/ always returns a REAL (decimal) result, even when the numbers divide evenly.DIV returns the integer quotient (the whole-number part of the division, truncated towards zero).MOD returns the remainder after integer division. Together: (A DIV B) * B + (A MOD B) = A.
DECLARE Total : INTEGER
DECLARE Count : INTEGER
DECLARE Average : REAL
Total <- 17
Count <- 5
Average <- Total / Count // 3.4 (REAL division)
OUTPUT Total DIV Count // 3 (integer quotient)
OUTPUT Total MOD Count // 2 (remainder)
OUTPUT Average // 3.4Notice how DIV truncates (drops the decimal) rather than rounding — 17 DIV 5 is 3, not 4, even though 17 ÷ 5 = 3.4 rounds to 3.
Arithmetic Operators
5 items8.2 Relational Operators
Relational operators compare two values and always produce aBOOLEAN result — either TRUE or FALSE. They are the building blocks of every IF condition and every loop condition.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| = | Equal to | 5 = 5 | TRUE |
| <> | Not equal to | 5 <> 6 | TRUE |
| < | Less than | 3 < 7 | TRUE |
| > | Greater than | 9 > 2 | TRUE |
| <= | Less than or equal to | 5 <= 5 | TRUE |
| >= | Greater than or equal to | 6 >= 8 | FALSE |
Important: = is Comparison, not Assignment
In CIE pseudocode, the single equals sign = is the comparison operator (it asks "are these equal?"), while the arrow <- is the assignment operator (it stores a value). This is different from languages like Python or Java where = assigns and == compares.
DECLARE Age : INTEGER
INPUT Age
IF Age >= 18 THEN
OUTPUT "You can vote."
ENDIF
IF Age <> 0 THEN
OUTPUT "Age is not zero."
ENDIF
IF Age = 18 THEN
OUTPUT "Exactly eighteen!"
ENDIFEach condition (Age >= 18, Age <> 0, Age = 18) evaluates to TRUE or FALSE, and the IF statement acts on that BOOLEAN result.
Relational Operators
5 items8.3 Logical Operators (AND, OR, NOT)
Logical operators combine or modify BOOLEAN values. They let you build complex conditions from simpler ones — for example, "age is at least 13 AND age is at most 19" describes a teenager. CIE pseudocode supports three logical operators.
AND
Returns TRUE only when both operands are TRUE. Acts like a strict gate — both conditions must pass.
OR
Returns TRUE when at least one operand is TRUE. Acts like a lenient gate — any one condition passing is enough.
NOT
A unary operator that inverts a single BOOLEAN value: NOT TRUE = FALSE, NOT FALSE = TRUE.
The truth tables below show every possible combination of inputs and the resulting output:
| A | B | A AND B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| FALSE | FALSE | FALSE |
| A | B | A OR B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
| A | NOT A |
|---|---|
| TRUE | FALSE |
| FALSE | TRUE |
DECLARE Age : INTEGER
DECLARE HasTicket : BOOLEAN
INPUT Age
INPUT HasTicket
IF Age >= 18 AND HasTicket = TRUE THEN
OUTPUT "Welcome to the show."
ENDIF
IF Age < 13 OR Age > 65 THEN
OUTPUT "Discount applies."
ENDIF
IF NOT HasTicket THEN
OUTPUT "Please buy a ticket first."
ENDIFLogical Operators
5 items8.4 Operator Precedence
When an expression contains several operators, CIE pseudocode evaluates them in a fixed order called operator precedence. Operators with higher precedence are evaluated first. Understanding this order is essential — getting it wrong is one of the most common sources of logic errors in exams.
| Order | Operator(s) | Category |
|---|---|---|
| 1 (highest) | ( ) | Parentheses — always evaluated first |
| 2 | * / MOD DIV | Multiplication, division, modulus |
| 3 | + - | Addition, subtraction |
| 4 | = <> < > <= >= | Relational (comparison) |
| 5 | NOT | Logical NOT (unary) |
| 6 | AND | Logical AND |
| 7 (lowest) | OR | Logical OR |
Memory Aid
Think of it as: Parentheses → Arithmetic → Relational → Logical ("PARL"). Within arithmetic: multiply/divide before add/subtract. Within logical: NOT, then AND, then OR.
// Example 1: Arithmetic precedence
OUTPUT 2 + 3 * 4 // 14, NOT 20 (* first, then +)
// Example 2: Parentheses override precedence
OUTPUT (2 + 3) * 4 // 20 (parentheses force + first)
// Example 3: Relational + Logical
// Age >= 13 is evaluated first (relational),
// then AND, then OR (lowest)
IF Age >= 13 AND Age <= 19 OR Age = 65 THEN
OUTPUT "Teenager or senior"
ENDIF
// Example 4: NOT has higher precedence than AND
IF NOT A AND B THEN
// means: (NOT A) AND B -- NOT applied to A first
ENDIFWhen in doubt, use parentheses to make your intended order explicit. Even if the default precedence would give the same result, parentheses make the code easier to read and remove ambiguity for both you and the examiner.
Operator Precedence
5 items8.5 Combining Operators
Real-world conditions rarely use a single operator. You will often combine arithmetic, relational, and logical operators in one expression — for example, to check whether a value falls in a range, or to test multiple criteria at once. The key is to read the expression using the precedence rules and to use parentheses liberally for clarity.
Range Check
To check if X is between 1 and 10 inclusive:
X >= 1 AND X <= 10Note: you CANNOT write 1 <= X <= 10 in pseudocode — each comparison must be separate.
Even/Odd Test
To check if N is even:
N MOD 2 = 0If the remainder when dividing by 2 is 0, the number is even.
DECLARE Score : INTEGER
DECLARE Attendance : INTEGER
INPUT Score
INPUT Attendance
// Combining arithmetic, relational, and logical operators
IF Score >= 80 AND Attendance >= 90 THEN
OUTPUT "Grade A with excellent attendance"
ELSE
IF Score >= 50 AND (Attendance >= 50 OR Score >= 90) THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF
// Using MOD to check for multiples
IF Score MOD 10 = 0 THEN
OUTPUT "Score is a multiple of 10"
ENDIFTip: Trace Step-by-Step
When faced with a complex expression, evaluate it in precedence order: first any parentheses, then arithmetic (* / MOD DIV before + -), then relational, then NOT, AND, OR. Write down each intermediate value to avoid mistakes.
Combining Operators
5 items8.6 Key Points Summary
Here is a quick recap of everything we've covered on operators:
- Six arithmetic operators — +, -, *, /, DIV, MOD. Use / for REAL division, DIV for integer quotient, MOD for remainder.
- Relational operators return BOOLEAN — =, <>, <, >, <=, >= always produce TRUE or FALSE. They are the basis of every condition.
- = is comparison, <- is assignment — In CIE pseudocode the single = asks "are these equal?" while <- stores a value. Do not confuse them.
- Three logical operators — AND (both true), OR (at least one true), NOT (inverts a single boolean). Memorise their truth tables.
- Precedence order: PARL — Parentheses, Arithmetic, Relational, Logical. Within arithmetic: * / MOD DIV before + -. Within logical: NOT, AND, OR.
- Use parentheses for clarity — When combining operators, parentheses make your intended order explicit and avoid precedence bugs.