Programming Algorithms
Senior 4 · ICT
Programming Algorithms
Lesson 3 of 5
25 min
In the 1960s and 1970s, programs were punched on cards and every run of the computer was booked in advance. A mistake could cost a day. So programmers planned on paper first, drawing their algorithms with plastic stencils like the one below, and only then wrote the code. Computers are now fast and cheap, but the habit survives because it works: an algorithm is easier to check, and to explain to others, in a form that does not depend on any programming language.

Definition
Pseudocode: an algorithm written in structured, precise English using a small set of keywords (INPUT, OUTPUT, IF, WHILE…) and indentation, close to a program but not tied to any language.
Flowchart: a diagram of an algorithm in which standard shapes stand for kinds of step and arrows (flow lines) show the order.
Control structures: the three ways steps can be combined: sequence (one after another), selection (choosing a path by a condition) and iteration (repeating). In 1966 Corrado Böhm and Giuseppe Jacopini showed that these three are enough to express any algorithm.
There is no single official pseudocode; examiners accept any clear, consistent style. This unit uses the following.
| Purpose | Pseudocode |
|---|---|
| Start and end | BEGIN … END |
| Input and output | INPUT x OUTPUT "text", x |
| Assignment | x ← expression |
| Selection (lesson 4) | IF condition THEN … ELSE … ENDIF |
| Iteration (lesson 5) | WHILE condition DO … ENDWHILE; REPEAT … UNTIL condition; FOR i ← 1 TO n … ENDFOR |
| Comment | // explanation for the reader |
Keywords are in capitals, variable names are meaningful, and the lines inside a structure are indented so its beginning and end are obvious.
Worked example 1: one algorithm, two forms
Problem: input three marks and output their average. This is pure sequence: each step runs once, in order. Each shape in the flowchart matches one line of pseudocode.
Trace with 64, 71 and 87: total = 222, average = .
Worked example 2: a flowchart with a decision
A school library charges 100 Frw for each day a book is late (an illustrative rate). Read the flowchart below and write the pseudocode.
The diamond becomes IF … THEN … ELSE … ENDIF: the Yes path goes after THEN, the No path after ELSE, and the point where the two paths join is ENDIF. Trace: daysLate = 3 gives fine = 300; daysLate = 0 gives fine = 0.
Stuff Made Easy: Flowcharts and Pseudocode, part 1. Watch how each flowchart shape is used and how the same algorithm is written in pseudocode; check that the shapes match the table above.
Warning
Every decision has two labelled exits. A diamond with one arrow out, or with arrows not marked Yes and No (or True and False), cannot be followed.
One Start, one Stop, and no dead ends. Every path through the chart must reach Stop. Use arrows on every flow line; a line without an arrowhead leaves the order unclear.
Pseudocode is not "almost Python". Do not mix in a language's special symbols (such as // for division or : after IF); keep to the agreed keywords.
Tip
Draw it in Google Drawings. In Google Docs, Insert → Drawing → New (Unit 1, lesson 4) offers the flowchart shapes under Shape → Shapes, and elbow connectors that stay attached when you move a shape.
Practice
total ← a + b then OUTPUT total. Selection: IF mark ≥ 50 THEN OUTPUT "Pass" ENDIF. Iteration: WHILE n > 0 DO n ← n - 1 ENDWHILE.Key points
Sources and credits
This lesson adapts CC BY-SA material and is shared under CC BY-SA 4.0.
BEGIN
INPUT daysLate
IF daysLate > 0 THEN
fine ← daysLate * 100
ELSE
fine ← 0
ENDIF
OUTPUT fine
ENDQuick check
Match each step to its flowchart symbol.
Tap one on the left, then its partner on the right.