- Describe what pseudocode is and explain its purpose in program design
- Read and interpret pseudocode that includes sequence, selection, and repetition
- Write structured-English pseudocode, adding refinements where detail is needed
- Explain the advantages and disadvantages of pseudocode as a design notation
- 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 a clear algorithm in structured English and refine steps that need detail
- I can use numbering and indentation as optional aids to clarity
- I can describe decisions and fixed or conditional loops in words, with clear block boundaries
- I can give one advantage and one disadvantage of pseudocode
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
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 structured English — 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. Structured English combines ordinary words with explicit conditions, repetition and actions so the algorithm can be checked before implementation.
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.
SQA uses reference language in question papers. You need to be able to read it. You will never be asked to write it.
Three things, three jobs
- Pseudocode: write structured English for design questions.
- SQA reference language: read only — read, trace and explain supplied code.
- Python: write for code questions.
Main steps and refinements
A useful method is to write an algorithm of main steps, then add refinements where more detail is needed. This lesson models that method; a separate two-part layout is not a marking requirement.
Main steps give the top-level overview of the algorithm. Optional numbers such as 1, 2, 3… help identify steps. 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 supply the detail needed to understand and check a main step. Optional numbers such as 1.1 and 1.2 show which step is being refined. A refinement may become several lines of code; a step that is already clear needs no extra detail.
Clear logic matters. Numbering, indentation and a separate refinements section can help a reader follow your design, but none earns a mark simply by being present. A clear detailed list can also communicate a valid design.
Including selection and repetition
A selection chooses actions according to a condition. Repetition repeats actions. The course specification, pseudocode appendix (printed pp49–50), says selection and repetition may be highlighted with indentation. Here we use indentation and natural-language boundaries to make the blocks easy to follow.
Describe a decision and both outcomes in structured English:
If score is at least 50
Display Pass
Otherwise
Display Fail
End selection
A fixed loop repeats a known number of times:
Set total to 0
Start fixed loop for each of the 30 pupils
Get score from user
Calculate total by adding score to total
End fixed loop
A conditional loop repeats until its condition is met:
Start conditional loop
Ask user for an answer
If answer is incorrect
Display Please try again
End selection
Repeat until answer is correct
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 the necessary inputs, calculations, conditions and outputs are clear. This helps when implementing and testing the design.
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.
Worked examples
Problem: Write pseudocode for a program that calculates the volume of a swimming pool.
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
1.1 Get length of pool in metres from user 1.2 Get width of pool in metres from user 1.3 Get depth of pool in metres from user
2.1 Calculate volume as length multiplied by width multiplied by depth 3.1 Display the volume of the pool in cubic metres
For a pool 10 metres long, 5 metres wide and 2 metres deep, the volume is 10 × 5 × 2 = 100 cubic metres. Add detail where it helps; do not force extra refinements onto an already clear step.
Problem: Write pseudocode for a program that takes 20 scores from the user, calculates the average, and displays whether the class passed (average ≥ 50).
Algorithm 1 Initialise variables 2 Get scores 3 Calculate average 4 Display result
1.1 Set total to 0 2.1 Start fixed loop for each of the 20 pupils 2.2 Get score from user 2.3 Calculate total by adding score to total 2.4 End fixed loop
3.1 Calculate average as total divided by 20 4.1 If average is at least 50 4.2 Display The class passed and the average 4.3 Otherwise 4.4 Display The class did not pass and the average 4.5 End selection
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.
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.
Algorithm 1 Get valid age from user 2 Display confirmed age
1.1 Get age from user 1.2 If age is below 0 or above 120 1.3 Start conditional loop 1.4 Display Invalid age. Please enter an age between 0 and 120 inclusive 1.5 Get age from user 1.6 Repeat until age is between 0 and 120 inclusive 1.7 End selection
2.1 Display the confirmed age
The first Get age from user is a priming read: it supplies the age before the first validity check. If that age is valid, the loop is skipped. Otherwise, the conditional loop displays an error and gets a new age until it is valid. Both 0 and 120 are valid; −1 and 121 are invalid.
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 20°C or is 20°C or below.
Write pseudocode for this program. Your design needs these logical steps; main steps with refinements are one useful way to organise them:
- Set the total to 0 before getting the readings
- A fixed loop to get and total exactly 5 temperatures, then calculate their average
- A selection to display the correct message and average for both outcomes
Pseudocode — structured-English design:
Algorithm 1 Initialise variables 2 Get temperatures 3 Calculate average 4 Display result Refinements 1.1 Set total to 0 2.1 Start fixed loop for each of the 5 readings 2.2 Get temperature from user 2.3 Calculate total by adding temperature to total 2.4 End fixed loop 3.1 Calculate average as total divided by 5 4.1 If average is above 20 4.2 Display Above 20°C and the average 4.3 Otherwise 4.4 Display 20°C or below and the average 4.5 End selection
Mark yourself: ✓ total starts at 0 · ✓ exactly 5 readings · ✓ each reading is added inside the loop · ✓ average calculated after the loop · ✓ average compared to 20 · ✓ both outcomes displayed with the average. Accept any clear alternative design.
SQA reference language (read only)
DECLARE total AS REAL INITIALLY 0
DECLARE temperature AS REAL INITIALLY 0
DECLARE average AS REAL INITIALLY 0
FOR reading FROM 1 TO 5 DO
RECEIVE temperature FROM KEYBOARD
SET total TO total + temperature
END FOR
SET average TO total / 5
IF average > 20 THEN
SEND "Above 20°C " & average TO DISPLAY
ELSE
SEND "20°C or below " & average TO DISPLAY
END IF
Python — implementation
total = 0
for reading in range(5):
temperature = float(input("Enter temperature: "))
total = total + temperature
average = total / 5
if average > 20:
print("Above 20°C", average)
else:
print("20°C or below", average)
All three versions get exactly 5 readings. The reference-language loop includes both endpoints, 1 and 5. Python range(5) gives 0, 1, 2, 3, 4 — also 5 iterations. For the class example, range(20) gives 20 iterations, matching a reference-language loop from 1 to 20. Read the reference panel to compare the logic; do not copy its notation for a design answer.
Check the calculation with 18, 20, 22, 24, 26: total 110, average 22, so display Above 20°C. Five readings of 20 give total 100 and average 20, so display 20°C or below.
For a design question, write clear structured-English pseudocode. An algorithm with refinements can help you supply the necessary detail. For a code question, write Python. When reference language is supplied, read it to work out its behaviour.
SQA 2024 Q11(a)(i), marking instructions p6, gives four logic points for that validation design: a conditional loop, the correct condition for the valid range 5–75, input inside the loop and an error message inside the loop. A missing loop start or end was tolerated when interpreting the design. These are criteria for that question, not a universal keyword checklist.
In the 2024 commentaries, Candidate 14 Q11(a)(i), a minimalist design earned 4/4. Focus on making the intended logic clear, rather than adding numbering or keywords to try to earn marks.
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 design says “Start conditional loop; get a score; repeat until the score is at least 0”. What type of construct is this? TYPE 1
4. Which of the following is a disadvantage of pseudocode? TYPE 1
5. This design should get 10 numbers, total them, then display Positive if the total is above 0, or Zero or negative otherwise. Identify four logic errors and explain each correction. TYPE 2
Get number from user
Start fixed loop 9 times
Calculate total by adding number to total
End fixed loop
If total is below 0
Display Positive
Otherwise
Display Zero or negative
End selection
- Missing initialisation: set total to 0 before adding any numbers.
- Wrong count: repeat 10 times, not 9.
- Input outside the loop: move Get number from user inside so each iteration gets a new number.
- Wrong condition: test whether total is above 0 to choose Positive.
Set total to 0
Start fixed loop 10 times
Get number from user
Calculate total by adding number to total
End fixed loop
If total is above 0
Display Positive
Otherwise
Display Zero or negative
End selection
Mark yourself: ✓ initial total is 0 · ✓ 10 inputs are totalled · ✓ each new input is inside the loop · ✓ the two messages match positive and non-positive totals. Accept any clear alternative design with this logic.
6. A program asks a user to enter a PIN number. The PIN must be exactly 4 digits long; treat it as text so leading zeros are kept. The program keeps asking until the user enters a valid PIN, then confirms it was accepted. Write structured-English pseudocode for this program. Use refinements where more detail is needed. TYPE 2
Algorithm 1 Get valid PIN from user 2 Confirm PIN accepted Refinements 1.1 Get PIN as text from user 1.2 If PIN does not have 4 characters or contains a non-digit character 1.3 Start conditional loop 1.4 Display Invalid PIN. Must be 4 digits. 1.5 Get PIN as text from user 1.6 Repeat until PIN has 4 characters and every character is a digit 1.7 End selection 2.1 Display PIN accepted
Mark yourself: ✓ PIN is kept as text so leading zeros are preserved · ✓ validity checks both length and digit-only content · ✓ invalid input gets an error message and a new input inside the loop · ✓ valid first input skips the loop · ✓ confirmation follows validation. Accept any clear alternative design. Test 0123 as valid; 123, 12345 and 12a3 as invalid.
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 between 0 and 100 inclusive 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. Use a fixed loop and a decision in structured English. Add refinements where detail is needed. 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 Start fixed loop for each of the 10 exams 2.2 Get score from user 2.3 If score is greater than highest 2.4 Set highest to score 2.5 Display New high score! 2.6 End selection 2.7 End fixed loop 3.1 Display the highest score
Mark yourself: ✓ highest starts at 0 for non-negative scores · ✓ exactly 10 scores are entered inside the loop · ✓ each score is compared with highest · ✓ a greater score updates highest and displays New high score! · ✓ equal scores do not announce a new high · ✓ final highest displayed after the loop. Accept any clear alternative design.
Lesson context: This is SDD lesson 4, following structure diagrams and flowcharts. Teach three distinct jobs: pupils write structured-English pseudocode for designs, read SQA reference language, and write Python for code questions. The bridge shows the same temperature algorithm in all three forms.
Common misconceptions: Do not make Python or reference-language syntax the definition of pseudocode. Main steps with refinements are useful for planning; a clear detailed list is also acceptable. Numbering and indentation are optional clarity aids. Do not claim penalties for absent refinements or END keywords.
Assessment evidence: SQA 2024 Q11(a)(i) awards four logic points for its validation design: conditional loop, correct 5–75 condition, input inside the loop and error message inside the loop. The marking instructions tolerate a missing loop start/end. Candidate 14’s minimalist answer earned 4/4 in the 2024 commentaries. Use the sources in the exam tip; do not generalise this into annual exam-weight or formatting claims.
Differentiation: Q1–Q4 are auto-checked. Q5 tests four logic faults. Q6 validates a text PIN, including leading zeros; Q8 places a decision inside a fixed loop. Check age boundaries 0 and 120, temperature equality at 20, and tied highest scores. Accept any clear alternative design meeting the logic criteria.
SQA command words covered: "write pseudocode", "identify an error", "give an advantage/disadvantage", "describe".