SDD  ·  Software Design & Development

Design: Pseudocode

SDD · Lesson 4 of 18 Software Design & Development Approx 60 min
Learning intentions
  • Describe what pseudocode is and explain its purpose in program design
  • Read and interpret pseudocode that includes sequence, selection, and repetition
  • Write pseudocode using a numbered main steps and refinements structure
  • Explain the advantages and disadvantages of pseudocode as a design notation
Success criteria
  • I can explain what pseudocode is in my own words
  • I can read a piece of pseudocode and explain what it does step by step
  • I can write pseudocode for a simple algorithm using main steps and refinements
  • I can use correct numbering (1, 2, 3 / 1.1, 1.2) in my pseudocode
  • I can include selection (IF/ELSE) and repetition (FOR/WHILE) in my pseudocode
  • I can give one advantage and one disadvantage of pseudocode
Warm up — what do you already know?

Answer before the lesson begins. These check prior knowledge — it's fine if you're unsure.

1. Which of the following best describes pseudocode?

2. In pseudocode, what does a refinement do?

3. Which design technique from the previous lesson shows the structure of a program as a tree diagram?

Key vocabulary

Pseudocode
A text-based design technique that uses English-like statements to describe an algorithm — it has no strict syntax rules and cannot be run by a computer.
Algorithm
A precise sequence of steps that solves a problem — pseudocode is one way to represent an algorithm.
Main steps
The top-level numbered steps of a pseudocode design (1, 2, 3…) — these give a high-level overview of the algorithm.
Refinement
A numbered sub-step that breaks a main step into more detail (e.g. 2.1, 2.2…). Each refinement should map to roughly one line of real code.
Selection
A construct in pseudocode that represents a decision — written as IF / ELSE / END IF, it executes different steps depending on a condition.
Repetition
A construct in pseudocode that represents a loop — either a fixed loop (FOR / END FOR) or a conditional loop (WHILE / END WHILE).

Design: Pseudocode

What is pseudocode?

Pseudocode is a text-based design technique used to plan a program before writing real code. It describes the logic of an algorithm using English-like statements — there is no fixed syntax to follow, which means programmers can focus on the logic rather than worrying about the exact rules of a programming language.

The SQA specification describes pseudocode as "a natural language-based design methodology used to define an algorithm and refinement." It is intended to be read by humans, not run by computers. Pseudocode sits between a plain English description — which is too vague to be useful — and actual code, which requires you to know the precise syntax of a specific language.

Because pseudocode has no strict rules, it can be written in any text editor or on paper. Two programmers might write pseudocode slightly differently and both be correct. What matters is that the logic is clear and that anyone reading it could translate it into real code.

Main steps and refinements

Pseudocode is written in two parts: main steps and refinements.

Main steps give the top-level overview of the algorithm, numbered 1, 2, 3… They describe what the program does at a high level, using broad descriptions like "Get scores from user" or "Calculate average". Main steps are typically only a few words long.

Refinements break each main step into more detail, numbered 1.1, 1.2, 2.1, 2.2… and so on. Each refinement should be detailed enough that it maps to roughly one line of actual code. Not every main step needs refinements — if a step is already simple enough to code directly, it can be left without them.

This two-level structure is important. In the exam, marks are awarded specifically for showing main steps and refinements separately. Writing a flat list of detailed steps without the main step overview will lose marks.

Including selection and repetition

When a step involves a decision, you write it as a selection construct. When a step involves repeating instructions, you write it as a repetition construct. The SQA specification states that selection and repetition should be shown using indentation to make the structure clear.

A selection construct uses IF, ELSE, and END IF:

IF score >= 50 THEN
    Display "Pass"
ELSE
    Display "Fail"
END IF

A fixed loop (used when you know exactly how many times to repeat) uses FOR and END FOR:

FOR pupil FROM 1 TO 30
    Get score from user
    Add score to total
END FOR

A conditional loop (used when you repeat until a condition is met) uses WHILE and END WHILE:

WHILE answer is incorrect
    Ask user to try again
END WHILE

Why use pseudocode?

Pseudocode lets programmers plan an algorithm without getting distracted by syntax errors. It can be written quickly in any text editor or even on paper. It is also easy to show refinements progressively — a complex main step can be broken down until each refinement maps to one line of real code. This makes translation from design to code straightforward.

However, pseudocode has a drawback: there is no universal standard notation. Different schools, companies, and textbooks use different conventions, which can cause confusion when sharing designs. It also does not show the flow of a program as visually as a flowchart does — loops and branches are less immediately obvious in text than in a diagram.

Key point from the SQA spec: In the exam, the SQA uses their own standardised reference language in questions. You are not required to mirror that exact style in your answers — marks are awarded for demonstrating understanding of the logic, not for using specific keywords or formatting.

Worked examples

Example 1 — Swimming pool volume (sequence only)

Problem: Write pseudocode for a program that calculates the volume of a swimming pool.

1
Write the main steps first — identify the three top-level tasks: get the dimensions, calculate the volume, display the result.
Algorithm
1  Ask user to enter dimensions of a swimming pool in metres
2  Calculate volume of pool
3  Display message stating the volume of the pool
2
Write refinements for step 1 — getting three separate dimensions requires three sub-steps.
1.1  Ask user to enter length of pool
1.2  Ask user to enter width of pool
1.3  Ask user to enter depth of pool
3
Write refinements for steps 2 and 3. Step 2 is a single calculation; step 3 is a single display. Each needs only one refinement.
2.1  Volume = length * width * depth
3.1  Display "The volume of the pool is", volume

Notice that step 2 only needs one refinement because the calculation is a single operation. You do not have to force multiple refinements onto a simple step.

Example 2 — Class average (fixed loop + selection)

Problem: Write pseudocode for a program that takes 20 scores from the user, calculates the average, and displays whether the class passed (average ≥ 50).

1
Identify the main steps: initialise, get scores, calculate, display.
Algorithm
1  Initialise variables
2  Get scores
3  Calculate average
4  Display result
2
Refine step 1 (initialise total to 0) and step 2 (a FOR loop over 20 pupils).
1.1  Set total to 0
2.1  FOR pupil FROM 1 TO 20
2.2      Get score from user
2.3      Set total to total + score
2.4  END FOR
3
Refine steps 3 and 4. Step 4 needs an IF/ELSE to handle pass or fail.
3.1  Set average to total / 20
4.1  IF average >= 50 THEN
4.2      Display "The class passed. Average: ", average
4.3  ELSE
4.4      Display "The class did not pass. Average: ", average
4.5  END IF

Main step 2 (Get scores) contains a fixed loop in its refinements. Main step 4 (Display result) contains selection. Both use indentation to show structure clearly.

Example 3 — Input validation (conditional loop)

Problem: Write pseudocode for a program that asks the user to enter an age and keeps asking until a valid age (between 0 and 120 inclusive) is entered.

1
The main steps are straightforward: get a valid age, then display it.
Algorithm
1  Get valid age from user
2  Display confirmed age
2
Refine step 1. The program must ask once, then loop while the input is invalid. This is a conditional loop because we do not know in advance how many times it will repeat.
1.1  Get age from user
1.2  WHILE age < 0 OR age > 120
1.3      Display "Invalid. Please enter an age between 0 and 120"
1.4      Get age from user
1.5  END WHILE
3
Refine step 2 — a single display statement.
2.1  Display "Age entered: ", age

The WHILE loop keeps repeating as long as the age is outside the valid range. Note that the first Get age from user appears before the loop — this is called a "priming read" and ensures there is a value to test on the first iteration.

Now you try

A programmer is writing a program that asks the user to enter 5 temperatures, calculates the average, and displays a message saying whether the average is above or below 20°C.

Write pseudocode for this program. Your pseudocode must include:

  1. A main steps section (at least 4 main steps)
  2. A refinements section — include a fixed loop for getting the temperatures
  3. A selection construct (IF/ELSE) for the display step

Model answer:

Algorithm
1  Initialise variables
2  Get temperatures
3  Calculate average
4  Display result

Refinements
1.1  Set total to 0
2.1  FOR reading FROM 1 TO 5
2.2      Get temperature from user
2.3      Set total to total + temperature
2.4  END FOR
3.1  Set average to total / 5
4.1  IF average > 20 THEN
4.2      Display "Above average temperature: ", average
4.3  ELSE
4.4      Display "Below average temperature: ", average
4.5  END IF

Mark yourself: ✓ main steps present · ✓ fixed loop with correct range (1 TO 5) · ✓ total accumulated inside loop · ✓ average calculated after loop · ✓ IF/ELSE with correct condition · ✓ END IF present

Common mistakes
Missing END statements — Every IF needs an END IF; every FOR needs an END FOR; every WHILE needs an END WHILE. Leaving these out makes your pseudocode ambiguous — the examiner cannot tell where the block ends.
No refinements — Writing "2. Calculate total" and leaving it without any refinement loses marks. Show how the calculation is actually performed — e.g. "2.1 Set total to total + score".
Confusing main steps with refinements — Main steps (1, 2, 3) are the high-level overview. Refinements (1.1, 1.2…) are the detail underneath. Do not put detailed code inside main steps, and do not write a flat list with no distinction between the two levels.
No indentation in loops and IF statements — The SQA spec says selection and repetition should be shown with indentation. Forgetting this makes your pseudocode hard to read and can cost marks in questions that specifically ask you to show structure clearly.
Writing real code syntax — Pseudocode like print("hello") or for i in range(5): is Python, not pseudocode. Pseudocode should be language-independent — keep it in plain English, e.g. "Display "hello"" and "FOR counter FROM 1 TO 5".
Exam tip

In the exam, pseudocode questions often ask you to write a design for a given program, or to identify an error in a piece of pseudocode. When writing pseudocode:

  • Always use main steps and refinements — the examiner is checking for this two-level structure
  • Use indentation for IF / WHILE / FOR blocks to show which lines are inside the block
  • You do not need to use the SQA's exact reference language — plain English logic is fine, as long as the structure is clear
  • A mark is often awarded specifically for showing the loop correctly and another for the selection — never leave either out if the problem clearly needs them
  • When asked to identify an error, common targets are: missing END statements, absent refinements, incorrect loop range, and wrong condition in a WHILE or IF
Task Set

Questions 1–4 are auto-checked. Questions 5–8 are self-marked — write your answer, then reveal the model answer to check your work.

1. What does the refinement number 3.2 mean? TYPE 1

2. Which of the following is a correct reason to use pseudocode rather than a flowchart? TYPE 1

3. A programmer writes the line WHILE score < 0 in their pseudocode. What type of construct is this? TYPE 1

4. Which of the following is a disadvantage of pseudocode? TYPE 1

5. A programmer writes the following pseudocode. Identify one error and explain how it should be corrected. TYPE 2

Algorithm
1  Get numbers
2  Calculate total
3  Display total

1.1  FOR counter FROM 1 TO 10
1.2      Get number from user
1.3      Add number to running total
1.4  END FOR

Error: The running total is never initialised — there is no step setting the total to 0 before the loop begins. Without this, the total could start at an unpredictable value.

Correction: Add a refinement before the loop, e.g. 1.0 Set total to 0 (or renumber as 1.1 and shift the existing refinements).

Also acceptable: Main step 2 (Calculate total) has no refinement — the addition is happening inside the loop under step 1, so step 2 is redundant or misleading. Award the mark for any clearly identified error with a valid correction.

6. A program asks a user to enter a PIN number. The PIN must be exactly 4 digits long. The program keeps asking until the user enters a valid PIN, then confirms it was accepted. Write pseudocode for this program using main steps and refinements. TYPE 2

Algorithm
1  Get valid PIN from user
2  Confirm PIN accepted

Refinements
1.1  Get PIN from user
1.2  WHILE length of PIN is not equal to 4
1.3      Display "Invalid PIN. Must be 4 digits."
1.4      Get PIN from user
1.5  END WHILE
2.1  Display "PIN accepted"

Mark yourself: ✓ main steps and refinements shown · ✓ WHILE loop with correct condition · ✓ error message inside loop · ✓ second "Get PIN" inside loop (priming read before loop) · ✓ END WHILE present · ✓ confirmation displayed after loop

7. Give one advantage and one disadvantage of pseudocode as a design technique. TYPE 2

Advantage (any one of):

  • Can be written quickly without worrying about programming language syntax
  • No special tools required — can be written on paper or in any text editor
  • Easy to show refinements progressively, making translation to code straightforward

Disadvantage (any one of):

  • There is no standard notation, so different programmers may write it differently, causing confusion
  • Does not show the flow of the program as clearly as a flowchart (loops and branches are less visually obvious)

8. A program takes 10 exam scores from a user, finds the highest score, and displays the message "New high score!" each time a score beats the current highest. After all scores have been entered, the program displays the final highest score. Write pseudocode for this program. Your pseudocode must use a fixed loop, a selection construct, and show main steps and refinements. TYPE 3

Algorithm
1  Initialise variables
2  Get scores and track highest
3  Display final result

Refinements
1.1  Set highest to 0
2.1  FOR exam FROM 1 TO 10
2.2      Get score from user
2.3      IF score > highest THEN
2.4          Set highest to score
2.5          Display "New high score!"
2.6      END IF
2.7  END FOR
3.1  Display "The highest score was: ", highest

Mark yourself: ✓ highest initialised to 0 · ✓ FOR loop 1 TO 10 · ✓ score entered inside loop · ✓ IF inside the loop comparing score to highest · ✓ highest updated when condition is true · ✓ "New high score!" displayed inside IF · ✓ END IF before END FOR · ✓ final display after loop · ✓ main steps and refinements clearly separated

Teacher notes — Shift+T to hide

Lesson context: This is SDD lesson 4. Pupils have seen structure diagrams (SDD2) and flowcharts (SDD3). This lesson introduces the third design notation. Key distinction to reinforce: pseudocode has no strict standard — the SQA uses their own reference language in exam questions but pupils are NOT required to mirror it exactly when answering.

Common misconceptions: Pupils frequently write Python or VB syntax instead of English-like pseudocode. Remind them that pseudocode is a planning tool — it should be language-independent. Also common: writing a flat numbered list with no distinction between main steps and refinements, which loses the structural marks.

Exam weight: Design questions appear every year. Pseudocode is assessed both in "write a design" questions and in "identify an error in this design" questions. The latter often penalises missing END statements or absent refinements. It is worth spending time on Q5 in class — error-spotting is a testable skill.

Differentiation: Q1–Q4 (TYPE 1) are accessible to all. Q6 (PIN validation with WHILE) and Q8 (nested IF inside FOR) are more challenging. Q8 is the hardest task — a loop containing a conditional. This pattern recurs throughout later SDD lessons (arrays, standard algorithms), so it is worth spending time on it here.

SQA command words covered: "write pseudocode", "identify an error", "give an advantage/disadvantage", "describe".