Writing algorithms in pseudocode
Pseudocode is a way of writing an algorithm in short, code-like English. It lets you plan a program without worrying about the rules of one language.
What is pseudocode?
There is no single official version: the aim is to be clear and precise.
Common keywords: INPUT, OUTPUT, IF ... THEN ... ELSE ... ENDIF, FOR ... ENDFOR, WHILE ... ENDWHILE.
An arrow β means store a value in a variable, for example score β 0.
The three building blocks
| Building block | Pseudocode example |
|---|---|
| Sequence | INPUT x then x β x * 2 then OUTPUT x |
| Selection | IF age >= 13 THEN ... ELSE ... ENDIF |
| Iteration (count-controlled) | FOR count β 1 TO 4 ... ENDFOR |
| Iteration (condition-controlled) | WHILE n < 50 ... ENDWHILE |
Tracing pseudocode
total β 0
FOR count β 1 TO 4
total β total + count
ENDFOR
OUTPUT total
count takes 1, 2, 3, 4. total goes 0, 1, 3, 6, 10.
Output: 10
What is output by this algorithm?
n β 1
WHILE n < 50
n β n * 3
ENDWHILE
OUTPUT n
- n starts at 1. 1 < 50, so n β 3.
- 3 < 50, so n β 9.
- 9 < 50, so n β 27.
- 27 < 50, so n β 81.
- 81 is not less than 50, so the loop stops.
Answer: 81
Pseudocode describes an algorithm in precise, code-like English using keywords such as INPUT, OUTPUT, IF, FOR and WHILE. Trace it line by line, keeping track of every variable.
- Algorithm
- A precise set of step-by-step instructions to solve a problem or complete a task.
- Program
- A set of instructions written in a programming language that a computer can run.
- Input
- Data put into a computer, for example from a keyboard, mouse, microphone or sensor.
- Output
- Information sent out from a computer, for example to a screen, speaker or printer.
- AND
- A Boolean operator that gives True (1) only when both inputs are True.
- Variable
- A named store in memory that holds a value, which can change while the program runs.
- Not βComputers can only understand pseudocodeβ. Computers cannot run pseudocode directly; it must be turned into a real programming language.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
What is output when the input is 4?
INPUT x
x β x * 2
x β x + 5
OUTPUT xShow the answer
Answer: 13
4 Γ 2 = 8, then 8 + 5 = 13.
What is output when the input is 9?
INPUT age
IF age >= 13 THEN
OUTPUT "You can join"
ELSE
OUTPUT "Too young"
ENDIFShow the answer
Answer: Too young
9 >= 13 is false, so the ELSE branch runs.
Check you have got it
Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.
Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.