| Component | Pseudocode |
|---|---|
| Start of test | IF condition THEN |
| True block | … statements … |
| Else clause (optional) | ELSE |
| False block (optional) | … statements … |
| End of construct | END IF |
IF mark ≥ 40 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
END IF
END IF – the compiler cannot determine where the block finishes.=) instead of a comparison operator (= =, ≠, <, >).ELSE without a preceding IF or writing two ELSE clauses.IF outer_condition THEN
IF inner_condition THEN
… statements …
ELSE
… statements …
END IF
ELSE
… statements …
END IF
IF score ≥ 70 THEN
OUTPUT "Distinction"
ELSE
IF score ≥ 50 THEN
OUTPUT "Merit"
ELSE
OUTPUT "Pass"
END IF
END IF
CASE statement or a separate function.is_premium rather than m).IF‑ELSE statements.| Component | Pseudocode |
|---|---|
| Start | CASE expression OF |
| Branch | value1: … statements … |
| Branch | value2: … statements … |
| Default | OTHER: … statements … |
| End | END CASE |
CASE mark OF
90 TO 100: OUTPUT "A+"
80 TO 89 : OUTPUT "A"
70 TO 79 : OUTPUT "B"
60 TO 69 : OUTPUT "C"
OTHER : OUTPUT "Fail"
END CASE
Problem statement
IF order_total ≥ 100 THEN
shipping_cost ← 0
ELSE
IF membership = "Premium" THEN
shipping_cost ← 5
ELSE
shipping_cost ← 10
END IF
END IF
OUTPUT "Shipping cost: £", shipping_cost
IF order_total ≥ 100 THEN
shipping_cost ← 0
ELSE
IF membership = "Premium" THEN
shipping_cost ← 5
ELSE
shipping_cost ← 10
END IF
END IF
OUTPUT "Shipping cost: £", shipping_cost
IF order_total ≥ 100 THEN
shipping_cost ← 0
ELSE
CASE membership OF
"Premium": shipping_cost ← 5
OTHER : shipping_cost ← 10
END CASE
END IF
OUTPUT "Shipping cost: £", shipping_cost
IF … THEN, ELSE and END IF.≥, =) rather than assignment.| Structure | Best for | Key feature |
|---|---|---|
| IF‑ELSE | Two possible outcomes, or a simple true/false test. | Explicit true and false blocks; easy to nest. |
| CASE / SWITCH | One variable with many discrete values. | One‑line branches; default (OTHER) branch handles unexpected values. |
| Nested IF | Multiple independent conditions that must be evaluated in sequence. | Hierarchical decision‑making; can become hard to read if over‑nested. |
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.