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.

Practise this lesson free (6 questions)

What is pseudocode?

Pseudocode looks a bit like a program, but it is written for people, not computers.
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

Sequence, selection and iteration all appear in pseudocode.
Building blockPseudocode example
SequenceINPUT x then x ← x * 2 then OUTPUT x
SelectionIF age >= 13 THEN ... ELSE ... ENDIF
Iteration (count-controlled)FOR count ← 1 TO 4 ... ENDFOR
Iteration (condition-controlled)WHILE n < 50 ... ENDWHILE

Tracing pseudocode

To trace an algorithm, follow it line by line and keep track of each variable.
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
Worked example

What is output by this algorithm?
n ← 1
WHILE n < 50
n ← n * 3
ENDWHILE
OUTPUT n

  1. n starts at 1. 1 < 50, so n ← 3.
  2. 3 < 50, so n ← 9.
  3. 9 < 50, so n ← 27.
  4. 27 < 50, so n ← 81.
  5. 81 is not less than 50, so the loop stops.

Answer: 81

Key idea

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.

Key words
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.

All KS3 Computing key terms and definitions β†’

Common mistakes
Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. What is output when the input is 4?
    INPUT x
    x ← x * 2
    x ← x + 5
    OUTPUT x

    Show the answer

    Answer: 13

    4 Γ— 2 = 8, then 8 + 5 = 13.

  2. What is output when the input is 9?
    INPUT age
    IF age >= 13 THEN
    OUTPUT "You can join"
    ELSE
    OUTPUT "Too young"
    ENDIF

    Show 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.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

Related lessons