Not sure which lesson to do first? Find your level and get a plan →

CS Thinking · Software Design & Development · Grade 6-8

Pseudocode

An informal, human-readable description of an algorithm using structured language that resembles code but is not tied to any specific programming language.


Quick Answer

An informal, human-readable description of an algorithm using structured language that resembles code but is not tied to any specific programming language. You write it after you know what a program must do and before you write real code: each line is one clear action, and words like IF, WHILE and FOR show the decisions and repeats. Because it skips semicolons, brackets and types, a classmate who codes in Python and one who uses Scratch can both read it and turn it into a working program.

Why This Matters

Most bugs in a first program are logic mistakes, not typing mistakes: a loop that stops one item early, a test that says greater than where you meant greater than or equal. Pseudocode lets you find those by tracing the plan with sample values before any code exists. It also lets you explain your plan to a teammate who uses a different language, and it is how algorithms are written in textbooks and coding interviews.

Intuitive Explanation

Imagine writing instructions for a robot that sorts mail, before you know which robot you will buy. You cannot use any one robot's commands, so you write: FOR each letter in the pile, IF the postcode starts with 9 THEN put it in bin A ELSE put it in bin B. That is pseudocode. The capital words carry the structure (repeat, decide), and plain English carries the actions.

Good pseudocode sits at a particular level of detail. 'Sort the mail' is too vague: it hides the one decision the robot actually has to make. A line full of brackets, dots and a semicolon is too detailed: it is already Java, and a reader has to decode the syntax to see the logic. The useful level is one where every line could become one or two lines of real code, in any language, without the reader having to guess.

Pseudocode is not a program. A computer cannot run it, and there is no single correct spelling: one person writes SET total TO 0, another writes total ← 0, and both are fine. A Python program, by contrast, fails if you miss a colon, because a machine reads it. Ask who the reader is: if it is a person checking the logic, pseudocode is right; if it is a computer, it must be code. A flowchart holds the same logic as boxes and arrows instead of lines of text.

Think of it like this. Pseudocode works like a recipe written for any kitchen: 'bake until golden' instead of 'set oven model X3 to 190'. Any cook can follow it, whatever their oven. Unlike a recipe, though, every step must be exact enough to trace with real numbers, because the computer that eventually runs the code will not guess what you meant.

Core idea. Pseudocode lets you focus on logic without worrying about syntax. It's a planning tool, not a running program.


When to Use

Reach for pseudocode when you must plan an algorithm before coding, explain logic to someone who uses a different language, or trace a solution by hand with sample inputs. Questions that say 'write an algorithm' or 'describe the steps' usually want it. If the question asks you to show branches and loops as a picture, draw a flowchart instead; if it asks what the finished system must do for its users, that is a design specification.

Tip. Ask: Are the steps written as text lines with IF, WHILE or FOR, meant for a person, not a computer, to follow?

How to Recognize It

Look at the form the steps take and at who is meant to read them.

  1. Are the steps written as lines of text rather than drawn as boxes and arrows?

    Yes points to pseudocode. Shapes joined by arrows, with diamonds for decisions, make a Flowchart.

  2. Would a real interpreter reject the lines, as it would SET total TO 0 or REPEAT UNTIL done?

    Yes, and that is fine: it is pseudocode, written for people. If every line follows one language's exact rules, it is code in that language.

  3. Do the lines say how to get the answer, step by step, rather than what the finished program must achieve?

    Yes means pseudocode. A list of goals the program must meet, such as 'loads in 2 seconds', is a Design Specification.

  4. Is the question about the method itself, whatever form it is written in?

    Yes means it is about the Algorithm; pseudocode is just one way to write an algorithm down, alongside flowcharts and real code.

Pseudocode vs Algorithm vs Flowchart vs Design Specification

All four are made before or alongside code to plan a program, so their names get swapped. Ask whether you are looking at a method, the method written in words, the method drawn as shapes, or a list of what the finished program must do.

Pseudocode

Meaning
Pseudocode writes an algorithm as short lines of plain words plus IF, WHILE and FOR, without any one language's rules.
Key test
Text lines a person can trace, which no computer can run as written.
Example
WHILE guess NOT EQUAL secret, ASK for a new guess; then OUTPUT 'Correct'.

Algorithm

Meaning
An algorithm is the step-by-step method itself, whether it is spoken, written, drawn or coded.
Key test
The method, not the way it is written down.
Example
'Look at each card in turn and keep the largest seen so far' is an algorithm in any form.

Flowchart

Meaning
A flowchart draws an algorithm as shapes joined by arrows, with diamonds for yes/no decisions.
Key test
Drawn, not written; you follow arrows instead of reading lines.
Example
A Start oval, an input box for n, then a diamond 'n > 0?' with Yes and No arrows to two output boxes.

Design Specification

Meaning
A design specification lists what a program must do and how success will be checked, not the steps that do it.
Key test
Says what must be true at the end, not how to get there.
Example
'The quiz shows 10 questions, then the score out of 10, within 1 second' is a requirement, not pseudocode.

Formula & Notation

Worked Examples

Example 1 — Plan and trace a test-average program

Easy

Write pseudocode that reads 5 test scores, finds their average, and prints 'Pass' if the average is 60 or more, otherwise 'Retake'. Trace it with the scores 72, 55, 64, 48, 81.
Show the steps and the answer
  1. Start a running total: SET total TO 0.

    The scores arrive one at a time, so the algorithm needs a place to keep the sum, and it must start empty.

  2. Repeat for the inputs: FOR i FROM 1 TO 5: INPUT score, SET total TO total + score.

    Five scores means the same two actions five times, which is exactly what FOR expresses.

  3. After the loop: SET average TO total / 5. IF average >= 60 THEN PRINT 'Pass' ELSE PRINT 'Retake'.

    The division happens once, after all five scores are in; putting it inside the loop would divide partial sums.

  4. Trace: total becomes 72, 127, 191, 239, 320, so average = 320 / 5 = 64.

    64 >= 60 is true, so the IF branch runs and the plan prints 'Pass'.

Answer: SET total TO 0; FOR i FROM 1 TO 5: INPUT score, SET total TO total + score; SET average TO total / 5; IF average >= 60 THEN PRINT 'Pass' ELSE PRINT 'Retake'. For 72, 55, 64, 48, 81 it prints 'Pass' (average 64).

Takeaway: Write one action per line, show repeats with FOR and choices with IF, then trace with real numbers to test the logic before any code exists.

Example 2 — Pseudocode or real code?

Standard

Two students plan a program that counts the negative numbers in a list. Ana writes: 'SET count TO 0. FOR each n IN list: IF n < 0 THEN add 1 to count. PRINT count.' Ben writes: 'int count = 0; for (int n : list) { if (n < 0) count++; } System.out.println(count);' The teacher asked for pseudocode that a Scratch user could follow. Which plan fits, and what does it print for the list 4, -2, 0, -7, 3?
Show the steps and the answer
  1. Look at Ben's version: it has a type (int), braces, semicolons and count++.

    Those are Java rules. A Scratch user would have to learn Java syntax just to read it, so it is code, not pseudocode.

  2. Look at Ana's version: plain words plus SET, FOR and IF, one action per line.

    Each line matches a Scratch block (set variable, repeat, if, change by 1), so a reader in any language can follow it.

  3. Trace Ana's plan: 4 no, -2 yes (count 1), 0 no, -7 yes (count 2), 3 no.

    0 is not less than 0, so it is not counted; the condition n < 0 settles that, not a guess about whether zero is negative.

Answer: Ana's plan is pseudocode; Ben's is Java. Both print 2 for the list 4, -2, 0, -7, 3.

Takeaway: Two plans can hold identical logic; what makes one pseudocode is that no particular language's syntax is needed to read it.

Example 3 — Find the mistake: a step that hides the algorithm

Application

Leo is planning a program that finds the highest score in a list. He writes: 'Get the scores. Find the biggest one. Show it.' Find the mistake and correct it, then trace your version on 12, 31, 7, 31, 25.
Show the steps and the answer
  1. Ask whether a classmate could code 'Find the biggest one' without guessing.

    They could not: it does not say where to start or what to compare. The whole algorithm is hidden inside one vague line.

  2. Replace it with explicit steps: SET highest TO the first score. FOR each remaining score s: IF s > highest THEN SET highest TO s. PRINT highest.

    Starting from the first score rather than 0 means the plan still works if every score is negative.

  3. Trace: highest = 12; 31 > 12, so highest = 31; 7 is not bigger; 31 > 31 is false, so no change; 25 is not bigger.

    Using > means a tie keeps the current value; tracing the repeated 31 shows that choice was deliberate.

Answer: SET highest TO the first score; FOR each remaining score s: IF s > highest THEN SET highest TO s; PRINT highest. For 12, 31, 7, 31, 25 it prints 31.

Takeaway: If one line of pseudocode needs a whole algorithm to carry it out, break it into steps that each become a line or two of real code.

Where You'll See It

  • Outlining an essay before writing it

    You jot the main points in plain words first, then expand them into full sentences — pseudocode is the same rough-draft step before writing real code.

  • Giving directions without a specific car

    'Drive until the second light, then turn left' works in any car; pseudocode describes the logic in plain language so it works in any programming language.

  • Planning a board-game strategy

    Writing 'IF I roll a 6, move ahead and roll again, ELSE pass the dice' captures the decision logic without worrying about exact code syntax.

Common Mistakes

  1. The slip: Pseudocode must use real syntax like semicolons, brackets, and type declarations to be valid.

    Why it's tempting: It looks like code, so it seems like it should follow code's rules.

    Instead: Pseudocode is intentionally language-independent; adding syntax details defeats its purpose. Use plain words plus structure words like IF, WHILE, FOR.

  2. The slip: Vague pseudocode like 'handle the data' is good enough.

    Why it's tempting: It captures the gist, and you know what you meant, so it feels complete.

    Instead: Each step must be concrete enough that someone else could translate it to real code; 'handle the data' hides the actual logic.

  3. The slip: Pseudocode is a runnable program, so I can execute it.

    Why it's tempting: It contains IF/WHILE/FOR and reads like code, so it seems like a language a computer can run.

    Instead: Pseudocode is a planning/communication tool, not executable; you must translate it into a real programming language to run it.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. Trace this pseudocode: SET total TO 0. FOR EACH number IN [4, 7, 1]: SET total TO total + number. After the loop, PRINT total. What prints?

    Hint: Update total once for each number in the list.

  2. Trace: SET n TO 5. SET result TO 1. WHILE n > 1: SET result TO result × n, then SET n TO n − 1. After the loop, PRINT result. What prints?

    Hint: Keep a table of n and result for each pass.

  3. Trace: SET count TO 0. FOR i FROM 1 TO 10: IF i MOD 3 = 0 THEN add 1 to count. Then PRINT count. What prints?

    Hint: i MOD 3 = 0 means i divides evenly by 3.

  4. Write pseudocode that asks for a test score, then prints 'Pass' if the score is 50 or more and 'Retry' otherwise.

    Hint: You need one input step and one IF with an ELSE.

  5. Your teammate wants the steps of a login check shown as a diagram with boxes and arrows for a class presentation. Pseudocode or a flowchart?

    Hint: Which one is visual, and which one is text?

  6. A student's pseudocode for finding the largest number in a list is: 'Look at the numbers. Find the biggest. Print it.' Rewrite it so someone could code it.

    Hint: Say exactly what to remember, and what to compare at each step.

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Is there an official way to write pseudocode?

No single standard exists, but many courses and exam boards set their own. The AP Computer Science Principles reference sheet uses an arrow for storing a value and REPEAT n TIMES for loops, and British exam boards publish their own styles. Whatever style you use, keep it consistent within one answer, and use the style your exam expects so the marker can follow it quickly.

Can pseudocode use lists and functions?

Yes. You can write lines such as FUNCTION average(list) and RETURN total / LENGTH(list), or refer to scores[1] for an item, as long as each line is clear. Naming a function in pseudocode is a good way to split a big plan into parts that later become real functions. Say once how you count positions, because the AP reference sheet counts list positions from 1, while Python counts from 0.

How do I turn pseudocode into real code?

Go line by line. SET total TO 0 becomes total = 0 in Python, FOR EACH item IN list becomes for item in list:, and OUTPUT becomes print(). Words like IF and WHILE usually map straight onto the language's own, and anything vague, such as 'sort the names', becomes either a built-in function or a smaller plan of its own. A line you cannot translate shows the pseudocode was not exact enough yet.

Learning Path

← Before

Algorithm
Pseudocode

You are here

You need Algorithm first: the idea of a finite, ordered list of steps that solves a problem. Pseudocode adds a way to write those steps precisely, with IF, WHILE and FOR, so they can be checked and translated into any language. Next, Flowchart draws the same logic as shapes and arrows, and Design Specification describes what the whole system must do before anyone plans its algorithms.

See Also