How do we write an algorithm in pseudocode using assignment, input, output, selection and loops?
Write algorithms in pseudocode using input, output, assignment, selection (IF) and iteration (WHILE, FOR)
A focused answer to the O-Level Computing point on pseudocode. Writing algorithms with input, output, assignment, IF selection, and WHILE and FOR loops, in clear language-independent steps.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
SEAB wants you to write algorithms in pseudocode using the core building blocks: input, output, assignment, selection with IF, and iteration with WHILE and FOR. The central idea is that pseudocode is a plain, structured way to describe an algorithm in words and keywords, close to code but not tied to any one programming language, so you can plan the logic before writing Python.
The answer
What pseudocode is
Pseudocode is a structured, language-independent way of writing an algorithm. It uses a small set of keywords and plain phrases, with indentation to show structure. It does not have to run on a computer; its job is to make the logic clear and easy to translate into real code.
Input, output and assignment
- Input reads a value:
INPUT age - Output displays a value:
OUTPUT "Hello" - Assignment stores a value in a variable:
total = 0(read as "total becomes ").
Assignment puts the value on the right into the variable on the left. total = total + 5 means take the current total, add , and store the result back.
Selection with IF
Selection chooses between paths:
IF mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
The THEN branch runs if the condition is true; the ELSE branch runs otherwise. The ENDIF marks where the selection finishes.
Iteration with WHILE
A WHILE loop repeats while a condition is true. It is used when you do not know in advance how many times to loop:
count = 0
WHILE count < 5
OUTPUT count
count = count + 1
ENDWHILE
The condition is tested before each pass; something inside must move it toward false, or the loop never ends.
Iteration with FOR
A FOR loop repeats a known number of times using a counter:
FOR i = 1 TO 10
OUTPUT i
NEXT i
The counter i runs from to . Use FOR when the number of repetitions is fixed, and WHILE when it depends on a condition.
Examples in context
Example 1. An ATM PIN check. Pseudocode for a cash machine reads the PIN, then uses a WHILE loop that keeps asking while the PIN is wrong and attempts remain, with an IF inside to count attempts. Writing it in pseudocode first makes the security logic clear before any code is typed.
Example 2. Averaging exam marks. A teacher's algorithm uses a FOR loop to read a known number of marks into an accumulator, then divides by the count to find the average. Because the number of students is known, FOR is the natural choice, and the pseudocode maps almost directly to Python.
Try this
Q1. Write pseudocode that inputs a number and outputs "Even" or "Odd". [3 marks]
- Cue.
INPUT n;IF n MOD 2 = 0 THEN OUTPUT "Even" ELSE OUTPUT "Odd" ENDIF.
Q2. State when you would use a WHILE loop rather than a FOR loop. [2 marks]
- Cue. When the number of repetitions is not known in advance and depends on a condition.
Q3. Explain what score = score + 1 does. [2 marks]
- Cue. It takes the current value of
score, adds , and stores the result back inscore.
Exam-style practice questions
Practice questions written in the style of SEAB exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
Original5 marksWrite pseudocode for an algorithm that reads numbers and outputs their total. Use a FOR loop and an accumulator.Show worked answer →
Set a running total to zero, then add each input inside a loop:
total = 0
FOR i = 1 TO 10
INPUT number
total = total + number
NEXT i
OUTPUT total
The variable total is the accumulator: it starts at and grows by each number. The FOR loop runs exactly times, and the output happens once after the loop ends.
Markers reward initialising total to , a FOR loop running times, adding each number to the total, and outputting after the loop.
Original5 marksWrite pseudocode that keeps asking the user to enter a positive number, and stops only when they do, then outputs the number. Use a WHILE loop.Show worked answer →
Read once, then loop while the value is not valid:
INPUT number
WHILE number <= 0
OUTPUT "Please enter a positive number"
INPUT number
ENDWHILE
OUTPUT number
The first INPUT gives the loop something to test. The WHILE repeats while the number is not positive (), asking again each time, and exits as soon as a positive number is entered.
Markers reward an initial input, a WHILE condition that repeats while the input is invalid, a re-prompt inside the loop, and output after the loop.
Related dot points
- Define an algorithm and represent its sequence, selection and iteration using standard flowchart symbols
A focused answer to the O-Level Computing point on algorithms and flowcharts. What an algorithm is, the standard flowchart symbols, and how to show sequence, selection and iteration in a flowchart.
- Describe and trace linear search and binary search, and explain why binary search needs a sorted list
A focused answer to the O-Level Computing point on searching. How linear search checks each item in turn, how binary search halves a sorted list each step, and why binary search is faster but needs sorted data.
- Describe and trace the bubble sort, explaining how repeated passes of comparisons and swaps sort a list
A focused answer to the O-Level Computing point on sorting. How bubble sort compares neighbouring items and swaps them, how each pass moves the largest value to the end, and tracing the algorithm by hand.
- Use a trace table to follow variable values through an algorithm, and choose normal, boundary and invalid test data
A focused answer to the O-Level Computing point on tracing and testing. Building a trace table to track variables through an algorithm, and choosing normal, boundary and invalid test data to find errors.
- Use Python for loops with range and while loops with a condition, including accumulators and avoiding infinite loops
A focused answer to the O-Level Computing point on Python loops. Using for with range for a known count, while with a condition for an unknown count, building accumulators, and avoiding infinite loops.