Problem: “Find the highest mark in a class and list all students who achieved it”.
| Element | Cambridge convention |
|---|---|
| Keywords | UPPERCASE (IF, ELSE, FOR, WHILE, END IF, END FOR, BREAK, CONTINUE) |
| Identifiers | PascalCase or lower_case (e.g., totalScore) |
| Comments | Enclosed in // or placed on a separate line beginning with # |
| Indentation | 4 spaces per nesting level (prevents “dangling‑else” errors) |
| Operators | Arithmetic (+, –, *, /, MOD), relational (=, ≠, <, >, ≤, ≥), logical (AND, OR, NOT) |
| Operator | Expression | Gate Symbol |
|---|---|---|
| AND | A AND B | & (⋀) |
| OR | A OR B | ≥ (⋁) |
| NOT | NOT A | ¬ |
| Denary | Binary (8‑bit) | Hexadecimal |
|---|---|---|
| 0 | 0000 0000 | 00 |
| 13 | 0000 1101 | 0D |
| 255 | 1111 1111 | FF |
| -1 | 1111 1111 | FF |
| -128 | 1000 0000 | 80 |
Overflow example: Adding 120 (0111 1000) and 20 (0001 0100) gives 1000 1100, which as an 8‑bit two’s‑complement value represents –124. The result is an overflow error.
Given 10110100₂:
11010000₂ (binary 208)00010110₂ (binary 22)| Aspect | Key Details |
|---|---|
| ASCII | 7‑bit, 128 characters, e.g., ‘A’ = 65 (0100 0001₂) |
| Unicode (UTF‑8) | Variable‑length, covers world scripts; ‘Ω’ = 937 (CE B3 in hex) |
| Sample rate | Samples per second (e.g., 44 kHz = 44 000 samples s⁻¹) |
| Resolution (image) | Pixels in width × height (e.g., 1920 × 1080) |
| Colour depth | Bits per pixel – 24‑bit = 16 777 216 colours |
File‑size example (audio): 44 kHz, 16‑bit mono, 5 s → 44 000 × 16 × 5 ÷ 8 = 440 000 bytes ≈ 429 KiB.
| Unit | Value (bytes) |
|---|---|
| 1 KiB | 2¹⁰ = 1 024 B |
| 1 MiB | 2²⁰ = 1 048 576 B |
| 1 GiB | 2³⁰ = 1 073 741 824 B |
| 1 TiB | 2⁴⁰ = 1 099 511 627 776 B |
Image size calculation: 800 × 600 px, 24‑bit colour → 800 × 600 × 24 ÷ 8 = 1 440 000 B ≈ 1 406 KiB.
Run‑Length Encoding (RLE) example: 11110000 → (4,1)(4,0) (four 1s, four 0s) – a simple loss‑less compression.
| Component | Purpose |
|---|---|
| Header | Source/destination address, protocol type, length |
| Payload | Actual data being transmitted |
| Trailer | Error‑detection bits (e.g., CRC, checksum) |
| Type | Key(s) | Typical Use |
|---|---|---|
| Symmetric | Single secret key (same for encrypt & decrypt) | Bulk data encryption (e.g., AES) |
| Asymmetric | Public key + private key pair | Secure key exchange, digital signatures (e.g., RSA) |
Arduino‑based thermostat:
| Device | Category | Typical Data Type |
|---|---|---|
| Keyboard | Input | Text / character codes |
| Mouse | Input | Numeric (x, y coordinates) |
| Touchscreen | Input/Output | Numeric (coordinates) + Text |
| Temperature sensor | Input | Numeric (°C or °F) |
| Accelerometer | Input | Numeric (g‑force on three axes) |
| Speaker | Output | Sound wave (digital samples) |
| LED array | Output | Binary (on/off) or colour values |
| Storage Type | Typical Medium | Advantages | Disadvantages |
|---|---|---|---|
| Primary (RAM) | Volatile semiconductor | Fast access, random‑access | Lost when power removed |
| Secondary – Magnetic | HDD | Large capacity, cheap per GB | Mechanical wear, slower |
| Secondary – Optical | CD/DVD/Bluray | Portable, read‑only (archival) | Limited rewrite cycles |
| Secondary – SSD | Flash memory | No moving parts, fast random access | Higher cost per GB |
| Virtual memory | Hard‑disk paging file | Extends usable RAM | Slower than physical RAM |
| Cloud storage | Remote servers via Internet | Access from anywhere, redundancy | Depends on network, security concerns |
| Component | Function |
|---|---|
| NIC (Network Interface Card) | Provides MAC address, handles physical‑layer signalling |
| Switch | Connects devices within a LAN, forwards frames based on MAC |
| Router | Routes packets between different networks, uses IP addresses |
| Firewall | Filters traffic according to security rules (packet‑filter or stateful) |
| Wireless Access Point (WAP) | Provides Wi‑Fi connectivity, bridges wired and wireless segments |
CASE … OF … END CASE (often called SWITCH).BREAK to exit early, CONTINUE to skip to the next iteration.A selection statement placed inside another selection (or inside a loop). The inner IF is evaluated only when the outer condition is true.
INPUT mark
IF mark >= 0 AND mark <= 100 THEN
IF mark >= 80 THEN
SET grade = "A"
ELSE IF mark >= 70 THEN
SET grade = "B"
ELSE IF mark >= 60 THEN
SET grade = "C"
ELSE IF mark >= 50 THEN
SET grade = "D"
ELSE
SET grade = "F"
END IF
PRINT "Grade:", grade
ELSE
PRINT "Invalid mark – must be 0‑100"
END IF
INPUT mark
IF mark < 0 OR mark > 100 THEN
PRINT "Invalid mark"
ELSE
CASE mark DIV 10 OF
10, 9, 8: SET grade = "A"
7: SET grade = "B"
6: SET grade = "C"
5: SET grade = "D"
0 TO 4: SET grade = "F"
END CASE
PRINT "Grade:", grade
END IF
A loop placed inside another loop. The inner loop runs **completely** for each iteration of the outer loop.
If the outer loop executes m times and the inner loop executes n times, total iterations = m × n → O(m·n).
FOR i = 1 TO 10 DO
FOR j = 1 TO 10 DO
SET product = i * j
PRINT i, "×", j, "=", product
END FOR
END FOR
FOR row = 1 TO rows DO
FOR col = 1 TO cols DO
PRINT array[row][col], " "
END FOR
PRINT NEWLINE
END FOR
Iterate over a data set, then decide what to do with each element.
FOR n = 1 TO 50 DO
IF n MOD 2 = 0 THEN
PRINT n, "is even"
END IF
END FOR
| Method | Purpose | Typical Pseudocode (Cambridge style) |
|---|---|---|
| Linear Search | Find the first occurrence of a target value in a list/array. |
|
| Bubble Sort | Sort a numeric array in ascending order using repeated swaps. |
|
| Totalling / Counting | Calculate sum, count, average, maximum, minimum. |
|
| Pass | i | Array after inner loop |
|---|---|---|
| 1 | 1‑4 | 3 2 5 1 4 |
| 2 | 1‑3 | 2 1 3 4 5 |
IF age < 0 OR age > 120 THEN …Use a trace table with at least three test cases: normal, boundary, and error case.
INPUT score
IF IS_NUMERIC(score) = FALSE THEN
PRINT "Error – not a number"
ELSE IF score < 0 OR score > 100 THEN
PRINT "Error – out of range"
ELSE
PRINT "Score accepted:", score
END IF
INPUT n
IF n < 2 THEN
PRINT n, "is NOT a prime number"
STOP
END IF
SET isPrime = TRUE
FOR i = 2 TO FLOOR(SQRT(n)) DO
IF MOD(n, i) = 0 THEN
SET isPrime = FALSE
BREAK
END IF
END FOR
IF isPrime = TRUE THEN
PRINT n, "is a prime number"
ELSE
PRINT n, "is NOT a prime number"
END IF
| i | MOD(29,i) | isPrime |
|---|---|---|
| 2 | 1 | TRUE |
| 3 | 2 | TRUE |
| 4 | 1 | TRUE |
| 5 | 4 | TRUE |
The loop stops after i = 5 because FLOOR(√29) = 5. No divisor found → isPrime = TRUE.
Testing divisors only up to √n reduces the number of iterations from O(n) to O(√n), a noticeable improvement for large n.
n < 2? – Yes → “not prime”, End; No → continue.isPrime ← TRUEi ← 2 TO √n
MOD(n,i)=0?
isPrime ← FALSE, BREAKisPrime?
FOR loop. Format output in a grid (e.g., tab‑separated).CASE … OF … END CASE. Remember to validate the input first.FOR loop with an IF that uses MOD. Add a CONTINUE to skip odd numbers if you wish.FOR i = 1 TO 10 DO
FOR j = 1 TO 10 DO
j = j + 1 // error
END FOR
END FOR
Hint: The inner‑loop variable must not be altered inside the loop body; remove the assignment or replace it with CONTINUE if the intention was to skip an iteration.{7, 3, 9, 5} and target 9. Show the values of i, position and any BREAK occurrence.111100001111, write pseudocode that produces the RLE pairs and show the resulting list.Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.