Pseudocode should achieve one main thing: communicate the logic of a solution clearly to humans while staying easy to translate into real code. Think of it as a “human-readable blueprint” that removes guesswork: a reader should understand what happens, in what order, and under what conditions.
1) Clear goals for a pseudocode solution
Goal A: Readability (easy for humans to scan)
Readable pseudocode uses simple sentences, consistent structure, and a predictable flow. A reader should be able to skim the steps and still understand the algorithm’s shape.
- Prefer short lines that express one action.
- Group related steps (e.g., input, processing, output) with spacing or headings if helpful.
- Use consistent keywords (e.g.,
IF,ELSE,WHILE,FOR EACH).
Goal B: Unambiguity (only one reasonable interpretation)
Unambiguous pseudocode avoids vague verbs and unclear conditions. If two readers could interpret a step differently, rewrite it to specify exactly what to check or do.
- Replace “handle,” “process,” “deal with,” “check” with explicit actions.
- State conditions precisely (e.g.,
IF age >= 18instead ofIF old enough). - Specify what happens in each branch (including “do nothing” if that is intended).
Goal C: Completeness (no missing decisions or outputs)
Complete pseudocode includes all necessary inputs, decisions, loops, and outputs. A reader should not have to “fill in” missing steps.
- List required inputs and expected outputs.
- Include edge cases that change the flow (empty list, invalid input, ties, etc.).
- Ensure every decision has an outcome (e.g., both
IFandELSEwhen needed).
2) Guidelines for writing steps as precise actions
Write verb-first instructions
Start each step with a clear verb so the action is obvious. This makes pseudocode feel like a set of executable instructions.
Continue in our app.
You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.
Or continue reading below...Download the app
| Unclear | Clear (verb-first) |
|---|---|
User data | READ userAge |
Validation | IF userAge is not a number THEN DISPLAY "Enter a number" AND STOP |
Result | DISPLAY eligibilityMessage |
One responsibility per line
Each line should do one thing. If a line contains multiple actions joined by “and,” consider splitting it. This reduces hidden complexity and makes translation to code straightforward.
Before (too much in one line):
IF cart is empty THEN show error and return to shopping and log eventAfter (single responsibility per line):
IF cart is empty THEN DISPLAY "Your cart is empty" LOG "Empty cart checkout attempt" STOPMake conditions and actions explicit
Replace fuzzy language with measurable checks and concrete actions.
Before (vague):
IF password is strong THEN accept itAfter (explicit criteria):
SET hasMinLength TO (LENGTH(password) >= 12)SET hasNumber TO (password contains at least 1 digit)SET hasUppercase TO (password contains at least 1 uppercase letter)IF hasMinLength AND hasNumber AND hasUppercase THEN ACCEPT passwordELSE DISPLAY "Password must be 12+ chars and include a number and uppercase"Specify loop boundaries and stopping rules
Loops are a common source of ambiguity. Always state what you iterate over and when you stop.
Before (unclear loop):
Keep checking items until doneAfter (clear loop):
FOR EACH item IN items DO IF item is defective THEN ADD item TO defectiveItemsEND FOR3) Rules for consistent naming
Use descriptive identifiers
Names should reveal purpose. Prefer totalPrice over tp, studentCount over n (unless n is clearly defined and used locally).
- Good:
maxScore,isLoggedIn,shippingCost,selectedOption - Risky:
x,tmp,val,data(unless context makes them precise)
Avoid over-short names unless scope is tiny
Single-letter names can be acceptable for very small, local counters (i in a short loop), but avoid them for important values that appear across multiple steps.
Before (hard to track):
READ aREAD bSET r TO a - bDISPLAY rAfter (self-explanatory):
READ originalPriceREAD discountAmountSET finalPrice TO originalPrice - discountAmountDISPLAY finalPriceName inputs and outputs explicitly
Make it obvious what comes in and what must be produced. This prevents hidden assumptions like “where did that value come from?”
Example structure:
- Inputs:
orderItems,taxRate,couponCode - Outputs:
receiptTotal,appliedDiscount
Before (inputs/outputs implied):
Calculate total and show itAfter (inputs/outputs named):
INPUT: orderItems, taxRate, couponCodeOUTPUT: receiptTotalSET subtotal TO SUM of item.price FOR EACH item IN orderItemsSET appliedDiscount TO discount from couponCode (or 0 if invalid)SET receiptTotal TO (subtotal - appliedDiscount) * (1 + taxRate)DISPLAY receiptTotalBe consistent with naming style
Pick a style and stick to it throughout the chapter/solution (e.g., camelCase like totalCost, or snake_case like total_cost). Consistency reduces cognitive load.
- Use
is...orhas...prefixes for boolean values:isAdult,hasPermission. - Use plural names for collections:
scores,items,errors.
4) Checklist to validate clarity
Clarity checklist (use before you finalize)
- Another person can follow it: Could a classmate execute the steps manually with sample input and get the same output you expect?
- No missing decisions: For every
IF, is it clear what happens when the condition is false? Are all important cases covered (including edge cases)? - No hidden assumptions: Did you state where inputs come from, what format they have, and what to do if they are invalid?
- Every variable is introduced: Are all variables set before they are used? Are names consistent (no accidental renaming like
totalvstotalPrice)? - Each step is a precise action: Do lines start with clear verbs (
READ,SET,ADD,DISPLAY,STOP) and avoid vague verbs? - One responsibility per line: Are multi-action lines split into smaller steps where needed?
- Easy to translate into code: Could you map each line to one or a few code statements without inventing missing logic?
Mini “before/after” fixes for common unclear steps
| Before (unclear) | After (explicit pseudocode) |
|---|---|
Sort the list and remove duplicates | SORT numbers in ascending orderSET uniqueNumbers TO empty listFOR EACH num IN numbers DO IF num is not in uniqueNumbers THEN ADD num TO uniqueNumbersEND FOR |
If the user is valid, continue | IF username exists in Users AND password matches stored password THEN SET isAuthenticated TO trueELSE DISPLAY "Invalid login" STOP |
Compute the average | IF LENGTH(scores) = 0 THEN DISPLAY "No scores" AND STOPSET sumScores TO 0FOR EACH score IN scores DO ADD score TO sumScoresSET averageScore TO sumScores / LENGTH(scores)DISPLAY averageScore |
Apply discount when appropriate | IF customerType = "student" THEN SET discountRate TO 0.10ELSE SET discountRate TO 0SET finalTotal TO subtotal * (1 - discountRate) |