Every algorithm, no matter how complex, is built from just three fundamental structures: sequence, selection, and iteration. These are sometimes called the three constructs of structured programming. Understanding them in pseudocode is the key to being able to plan and communicate any algorithm clearly.
1. Sequence
Sequence simply means that instructions execute one after another in order, from top to bottom. It is the default structure.
SET price ← 12.99
SET quantity ← 3
SET total ← price * quantity
OUTPUT "Total: £" + total
Each line runs once, in order. Nothing is repeated, nothing is skipped.
2. Selection
Selection (also called branching) allows the algorithm to choose between different paths based on a condition. In pseudocode this is written with IF, ELSE, and ENDIF.
IF score >= 70 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
Multiple branches use ELSE IF:
IF score >= 90 THEN
OUTPUT "Distinction"
ELSE IF score >= 70 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ELSE IF in pseudocode corresponds to elif in Python. It adds as many extra branches as you need without deeply nesting multiple IF blocks.
3. Iteration (Loops)
Iteration means repeating a block of steps. There are two key forms in pseudocode:
Count-controlled loop (FOR)
Use when you know how many times to repeat:
FOR counter ← 1 TO 5 DO
OUTPUT counter
ENDFOR
Condition-controlled loop (WHILE)
Use when repetition depends on a condition:
SET guess ← 0
WHILE guess ≠ 42 DO
INPUT guess
ENDWHILE
OUTPUT "Correct!"
Choose the right loop type when writing pseudocode. If you know the number of repetitions upfront, use FOR. If you are waiting for a condition to change, use WHILE.
Combining All Three Structures
Real algorithms combine all three constructs. Here is pseudocode for a number-guessing game:
SET secret ← 42
SET attempts ← 0
SET found ← FALSE
WHILE found = FALSE DO
INPUT guess
SET attempts ← attempts + 1
IF guess < secret THEN
OUTPUT "Too low"
ELSE IF guess > secret THEN
OUTPUT "Too high"
ELSE
OUTPUT "Correct! Attempts: " + attempts
SET found ← TRUE
ENDIF
ENDWHILE
This uses:
- Sequence — each step in order
- Iteration — the WHILE loop keeps going until the player guesses correctly
- Selection — the IF-ELSE IF-ELSE checks three different outcomes
When tracing pseudocode in an exam, work through each line carefully, updating variable values as you go. Keep a table of variable values — this helps you avoid making arithmetic mistakes mid-trace.
Nesting Structures
Structures can be nested inside each other. In the example above, the IF statement is nested inside the WHILE loop. This is perfectly normal and is how complex behaviour is built from simple building blocks.
Practice Problems
Identify the three structures (sequence, selection, iteration) in this pseudocode: SET total ← 0; FOR i ← 1 TO 10 DO; INPUT num; IF num > 0 THEN SET total ← total + num ENDIF; ENDFOR; OUTPUT total.
Show answer
Rewrite this Python code as pseudocode: count = 0; for n in range(1, 6): if n % 2 == 0: count += 1; print(count)