Imagine you have a brilliant idea for a program, but you haven't decided which language you'll write it in yet — Python? JavaScript? Something you'll learn next year? You don't want to get bogged down in semicolons and brackets while the idea is still forming. What you really want is a way to jot down the logic — the steps, the decisions, the repeats — in plain, tidy English, so you can think clearly first and worry about the exact code later.
That's exactly what pseudocode is. The word means "fake code": it looks like a program, but it isn't written in any real programming language and a computer can't run it. It's a halfway house between everyday English and real code — structured, near-English — written for humans to read while they plan out an algorithm.
There's no single official pseudocode, but almost everyone uses the same handful of ideas, written in
CAPITALS so the important "command" words stand out. These are the building blocks you
met as boxes in
| Convention | What it means |
|---|---|
INPUT name | Ask the user for a value and store it in name. |
OUTPUT thing | Show thing to the user (also written PRINT or DISPLAY). |
x ← 5 (or x = 5) | Assignment: put the value 5 into the variable x. The arrow points the value into the box. |
IF … THEN … ELSE … ENDIF | A decision: do one thing if a condition is true, otherwise do another. |
WHILE … ENDWHILE | A loop that repeats while a condition stays true. |
FOR count ← 1 TO 10 … NEXT count | A loop that repeats a fixed number of times, counting as it goes. |
Notice the pattern: a block that opens with a keyword usually closes with a matching one
(IF … ENDIF, WHILE … ENDWHILE), and everything inside a block is
indented. That indenting is what shows, at a glance, which lines belong to the
decision or the loop.
Let's plan a tiny program: ask for a test mark, and say whether it's a pass (50 or more) or a fail. In pseudocode we'd write it like this — read it top to bottom, like a recipe:
See how it reads almost like English? Anyone can follow the logic — no programming knowledge needed.
There's an INPUT, a single IF … ELSE … ENDIF decision, and the two possible
OUTPUTs are indented to show they live inside the decision.
Now here is the very same algorithm written as real, runnable TypeScript. A real
program can't stop and ask you to type while it runs here, so instead of INPUT we just
set mark to a value at the top — change the number and press Run again
to test both branches:
Line for line, the pseudocode and the code say the same thing. That's the whole point: the pseudocode
was the plan, and turning it into real code was almost a straight translation. The keywords
change (THEN becomes {, ENDIF becomes }), but the
logic is identical.
Decisions are only half the story — algorithms also repeat things. Suppose we want to
add up all the numbers from 1 to 5. In pseudocode we use a FOR loop and an accumulator
variable called total:
Read it as: start total at 0; let count run through 1, 2, 3, 4, 5, and each
time add count onto total; when the loop finishes, show the answer. Watch the
assignment arrow ← doing the work — total ← total + count means
"work out total + count, then store the result back in total."
Here it is as runnable TypeScript. Press Run to see the total appear:
Same algorithm, two forms. The pseudocode let us think about what should happen; the TypeScript makes it actually happen. If you can write the pseudocode, the code is usually just around the corner.
For a five-line program you often can! But real algorithms get tangled — nested loops, several decisions, edge cases. Sketching the logic in pseudocode first lets you spot a mistake in the thinking before you've buried it under brackets, semicolons and language rules. It's the same reason an architect draws a plan before laying bricks: it's far cheaper to fix a line on paper than a wall that's already built. Pseudocode is your program's plan.
Use a FOR loop when you know how many times to repeat ("do this
10 times", "for each of the 30 pupils"). Use a WHILE loop when you repeat
until some condition changes and you don't know the count in advance ("keep asking for a
password WHILE it's wrong", "keep halving the number WHILE it's bigger than
1"). A FOR loop counts; a WHILE loop watches.
Pseudocode is for humans, so there is no single official syntax — one
book writes OUTPUT, another writes PRINT; one uses ← for
assignment, another uses =. None of it will run on a computer. But that freedom is
not a licence to be sloppy: your pseudocode must still be unambiguous and show the
logic clearly, so that any reader turns it into the same program. Line up your
indentation, close your blocks (ENDIF, ENDWHILE), and make every step
explicit. In an exam you don't need to remember one "correct" set of keywords — sensible,
clear, consistent pseudocode is accepted. Vague pseudocode like "do the sorting bit" is not:
it hides the very logic you were meant to show.