Pseudocode
Between the Idea and the Code
You have an algorithm in your head. Writing it straight into a programming language means fighting two battles at once: getting the logic right and getting the syntax right — every comma, colon, and keyword. Writing it as loose English has the opposite problem: too vague to expose flaws.
Pseudocode is the deliberate middle ground: the structure of code with the freedom of English. It is written for humans — a computer cannot run it — and that is exactly its power. You design and check the logic first, then translate it into any real language afterwards.
You have already met the visual version of this idea: flowcharts. Pseudocode is its text-based sibling — quicker to write, easier to fit on a page, and closer in shape to the final program.
The Conventions
There is no official standard — pseudocode has no compiler to please — but a common style has grown up. Keywords in capitals, one instruction per line:
INPUT/OUTPUT— bring data in, send results out (inputs and outputs)←— assignment:score ← 0stores 0 in the variable scoreIF … THEN … ELSE … ENDIF— selectionWHILE … ENDWHILE,FOR … TO … NEXT,REPEAT … UNTIL— repetition- Indentation — everything inside a loop or IF is indented, so the structure is visible at a glance
Note the arrow: score ← score + 1 is not an equation (it would be nonsense as maths). It means work out the right side, store it in the left — the variable grows by one.
A Complete Example
A guessing game: the player keeps guessing until they find the secret number, then hears how many tries they took.
secret ← 7
tries ← 0
guessed ← false
WHILE guessed = false
OUTPUT "Enter your guess:"
INPUT guess
tries ← tries + 1
IF guess = secret THEN
OUTPUT "Correct! Tries: ", tries
guessed ← true
ELSE IF guess < secret THEN
OUTPUT "Too low"
ELSE
OUTPUT "Too high"
ENDIF
ENDWHILE
Read it aloud — it is nearly English. Yet every question a programmer needs answered is answered: what repeats, what decides, where the counter changes. All three fundamental structures are here — sequence, selection, repetition — and there is even a flag (guessed) controlling the loop, plus Boolean conditions steering the IFs. Any programming language could be built from this blueprint; the pseudocode is the algorithm, the language is just the handwriting.
Design First, Then Translate
The workflow pseudocode enables:
- Decompose the problem into parts
- Draft pseudocode for each part — fast, no syntax to look up
- Check the logic by tracing it: run through it by hand with sample values, hunting for flaws
- Translate into a real language, one line at a time
Step 3 is the payoff. Finding a logic error in four lines of pseudocode takes a minute. Finding the same error later, buried in real code under a pile of syntax, is a proper debugging session. Fixing mistakes early is cheap; that is the whole economics of planning.
Exams and job interviews love pseudocode for the same reason: it shows pure algorithmic thinking, with no marks lost to a missing semicolon.
Try It Yourself
Write pseudocode that reads 10 numbers and outputs the largest. (Plan: keep a variable biggest; start it with the first number; for each remaining number, IF it beats biggest, store it.) Then trace your draft with the inputs 3, 9, 4 — does it print 9? Now translate the same design into a flowchart and notice how the two representations mirror each other.
Worked Example — Pseudocode for a Multi-Step Problem
Larger problems benefit from writing pseudocode in stages, refining vague ideas into precise ones — a technique sometimes called stepwise refinement. Start with a rough plan for "calculate a shopping bill with a student discount":
Get the prices of all items
Add them up
If the customer is a student, apply a discount
Show the total
This is really just structured English — useful for planning, but too vague to trace or translate directly. Refine each line into proper pseudocode:
total ← 0
FOR EACH price IN itemPrices
total ← total + price
NEXT
IF isStudent THEN
total ← total * 0.9
ENDIF
OUTPUT "Total: £", total
Notice how the refinement process mirrors decomposition: a vague, high-level plan is broken down, one line at a time, until every line is precise enough to trace and eventually translate into a real programming language. Skilled programmers often work exactly this way — sketching a rough plan first, then refining it downward into detail — rather than trying to write perfectly precise pseudocode in one pass.
Key Words
- Pseudocode — structured plain-language description of an algorithm, written for humans
- Assignment (←) — storing a value in a variable
- Keyword — a structural word like IF, WHILE, INPUT, OUTPUT
- Indentation — inset lines showing what belongs inside a loop or condition
- Trace — executing pseudocode by hand to check its logic