Study Guide
Flowcharts and Pseudocode
How to write an algorithm down precisely: why everyday sentences are not exact enough, how to read and follow a flowchart and Cambridge pseudocode, and how to spot a line that breaks the rules.
Lesson 5.2 Algorithms and Programming
For: Complete beginners to programming: Key Stage 3 (about ages 11 to 14), or a Cambridge IGCSE Computer Science course
Stage: Think
A fare the app must get right
Greenway Buses (a fictional company) has a rule: “Children pay £1 and adults pay £2.” The company wants a ticket machine that asks for a passenger’s age and shows the fare. The programmer has the rule on a card, and has been told to write it as an algorithm.
Think it through
Could the programmer write the ticket machine from the rule “Children pay £1 and adults pay £2”? What does the machine need to know that the rule does not say?
- Hint 1: A passenger is 15 years old. What does the machine charge?
- Hint 2: What would two different programmers decide?
Show a model answer
The machine needs the exact age at which a passenger stops being a child. “Child” is not a number a computer can compare with. One programmer might pick 15, another 16, and passengers of that age would be charged differently by different machines. The rule has to name a number and say whether that number itself is included.
Stage: Discover
Being exact
Greenway’s manager settles it: “Anyone older than 15 pays £2.”
Think it through
Rule A says “older than 15 pays £2”. Rule B says “15 or older pays £2”. A passenger is exactly 15. Which fare does each rule give, and what does the difference tell you about the wording?
- Hint 1: Is 15 older than 15?
Show a model answer
Rule A gives £1: 15 is not older than 15. Rule B gives £2: 15 is “15 or older”. The two rules differ only for a passenger of exactly 15, so a small change of wording changes who pays what. An algorithm has to choose one of them, and say it so clearly that nobody can read it the other way.
Algorithms use symbols for comparisons, because symbols are exact and sentences are not:
| Symbol | Meaning | True for a 15-year-old? |
|---|---|---|
Age > 15 | Age is greater than 15 | No |
Age >= 15 | Age is greater than or equal to 15 | Yes |
Age < 15 | Age is less than 15 | No |
Age <= 15 | Age is less than or equal to 15 | Yes |
Age = 15 | Age is equal to 15 | Yes |
Age <> 15 | Age is not equal to 15 | No |
A test like Age > 15 is called a condition: it is either true or false. Examiners expect a condition to be written with these symbols. Age > 15 is acceptable; “Age is greater than 15” is not, because it is written in everyday language, which is where the confusion above comes from.
Check your understanding
Show the answer
Answer: B. Age > 15
For every age, each condition is exactly true or exactly false. That is what makes it precise.
Stage: Predict
A picture of the algorithm
An algorithm can be drawn as a flowchart: shapes joined by arrows. Here is the fare algorithm as a flowchart, set out as a table, one row per box, so that it can be read in order. The “Next” column is the arrow leaving each box.
| Box | Shape | Text inside the box | Next |
|---|---|---|---|
| 1 | Oval | START | Box 2 |
| 2 | Parallelogram | INPUT Age | Box 3 |
| 3 | Diamond | Age <= 15 ? | Yes: box 4. No: box 5 |
| 4 | Rectangle | Fare ← 1 | Box 6 |
| 5 | Rectangle | Fare ← 2 | Box 6 |
| 6 | Parallelogram | OUTPUT Fare | Box 7 |
| 7 | Oval | STOP | (none) |
Think it through
Without being told, guess: what job does each shape seem to do? In particular, which shape is the question with two ways out, which shapes mark the beginning and end, and which shape shows data going in or coming out?
- Hint 1: Look at which shape has two arrows leaving it.
Show a model answer
The diamond is the question: it is the only box with two ways out. The ovals mark the start and the stop. The parallelograms are where something goes in (INPUT) or comes out (OUTPUT). The rectangles do a piece of work: here, storing a fare.
Your guesses match the standard symbols that Cambridge examinations use:
| Symbol | Shape | What it means |
|---|---|---|
| Terminator | Oval (or rounded rectangle) | The START or STOP of the algorithm |
| Input/output | Parallelogram | Data going in or coming out |
| Process | Rectangle | Something being done, such as a calculation or storing a value |
| Decision | Diamond | A yes/no (true/false) question with two arrows out, labelled Yes and No |
| Subroutine | Rectangle with a second vertical line inside each side | A call to a separate, named part, which has its own flowchart |
| Flow line | Arrow | The order: control passes from one shape to the next |
Every flowchart starts with a terminator and ends with one. Every shape has one arrow leaving it, except a decision, which has two, and a terminator marking the stop, which has none. The subroutine symbol is not needed in this lesson.
Check your understanding
Show the answer
Answer: A. Two: one labelled Yes (or True) and one labelled No (or False).
A decision has exactly two arrows out, one for each answer.
Stage: Experiment
Following the arrows
To check that an algorithm works, follow it by hand with some input values and write down what happens. A table that records this is called a trace table. Follow the fare flowchart for four passengers. Each row is a separate passenger, so the algorithm starts again at the beginning each time.
| Age entered | Is Age <= 15? | Fare | OUTPUT |
|---|---|---|---|
| 9 | |||
| 15 | |||
| 16 | |||
| 40 |
- Start at box 1 for each row and follow the arrows.
Show the completed table
| Age entered | Is Age <= 15? | Fare | OUTPUT |
|---|---|---|---|
| 9 | Yes | 1 | 1 |
| 15 | Yes | 1 | 1 |
| 16 | No | 2 | 2 |
| 40 | No | 2 | 2 |
The fares are in pounds.
Check your understanding
Show the answer
Answer: B. It sits on the edge of the condition, so a wrong symbol such as < would give a different fare.
Values on the edge of a condition are the ones that expose a wrong comparison symbol.
Stage: Predict
The same algorithm in words
Flowcharts take space. Pseudocode writes the same algorithm as lines of text, using fixed keywords. It is not a real programming language, so no computer runs it, but it is exact enough to be turned into any language. This is the fare algorithm in Cambridge pseudocode:
INPUT Age
IF Age <= 15
THEN
Fare ← 1
ELSE
Fare ← 2
ENDIF
OUTPUT FareThink it through
You have not been taught this notation yet, but you have seen the flowchart. Read the pseudocode line by line and write what you think each line does. What do you think the arrow ← means?
- Hint 1: Compare each line with a box in the table of the flowchart.
Show a model answer
INPUT Age: ask for the age and keep it. IF Age <= 15: test the condition. THEN … ELSE …: the first block is carried out when the condition is true, the second when it is false. ENDIF: marks where the IF ends. OUTPUT Fare: show the fare. The arrow ← means “store the value on the right in the name on the left”: Fare ← 1 puts 1 into Fare.
These are the conventions Cambridge uses:
- Keywords are in capitals:
INPUT,OUTPUT,IF,THEN,ELSE,ENDIF. - Names the programmer chooses (here
AgeandFare) start with a capital letter, with a capital for each new word, as inTicketPrice. Names of this kind are called variables: places where a value is kept. Lesson 3 teaches them properly. - ← is the arrow of assignment: it stores the value on its right in the variable on its left.
- Indentation shows what belongs where.
THENandELSEare indented by two spaces and the lines inside them by four. EveryIFis closed by its ownENDIF. - Comments start with
//and are ignored:// child fare.
The arrow ← is not an equals sign. Fare ← 1 is an instruction: it puts 1 into Fare. Age = 15 is a question: it is true if Age holds 15 and false otherwise. Using = where an arrow is needed, as in Fare = 1, is one of the most common marks lost in pseudocode.
Check your understanding
Show the answer
Answer: C. The diamond (decision), because it asks a question with a yes or no answer.
The decision diamond corresponds to IF; its Yes arrow to THEN and its No arrow to ELSE.
Stage: Experiment
Matching lines to shapes
Use the table of symbols above. For each pseudocode line from the fare algorithm, name the flowchart shape it becomes.
| Pseudocode line | Flowchart shape |
|---|---|
| INPUT Age | |
| IF Age <= 15 | |
| Fare ← 2 | |
| OUTPUT Fare |
- The six symbols are in the table in the earlier step.
Show the completed table
| Pseudocode line | Flowchart shape |
|---|---|
| INPUT Age | parallelogram |
| IF Age <= 15 | diamond |
| Fare ← 2 | rectangle |
| OUTPUT Fare | parallelogram |
Stage: Apply
Following pseudocode
A school canteen till (fictional) works out change for a pupil. Prices and money are in pence, so that every value is a whole number.
INPUT Price
INPUT Money
Change ← Money - Price
IF Change < 0
THEN
OUTPUT "Not enough money"
ELSE
OUTPUT Change
ENDIFApply it
Show the answer
Answer: C. Not enough money
The condition decides the branch; Change is negative, so the THEN branch runs.
Now follow it for three pupils. Each row is a separate run.
| Price | Money | Change | OUTPUT |
|---|---|---|---|
| 150 | 200 | ||
| 120 | 100 | ||
| 80 | 80 |
Show the completed table
| Price | Money | Change | OUTPUT |
|---|---|---|---|
| 150 | 200 | 50 | 50 |
| 120 | 100 | -20 | Not enough money |
| 80 | 80 | 0 | 0 |
Check your understanding
Show the answer
Answer: A. Because 0 is less than 0 is false, so the condition Change < 0 is false.
Which branch runs depends only on whether the condition is true or false.
Stage: Apply
Mistakes in the pseudocode
Sam (fictional) writes the bus fare algorithm for the exam like this:
INPUT Age
IF Age is greater than 15
THEN
Fare = 2
ELSE
Fare = 1Apply it
Show the answer
Answer: A. The condition is in words, = stores the fares, and the IF has no ENDIF.
Three conventions are broken: precise conditions, the assignment arrow and the matching ENDIF.
Corrected:
INPUT Age
IF Age > 15
THEN
Fare ← 2
ELSE
Fare ← 1
ENDIF
OUTPUT FareSam had also forgotten the final OUTPUT Fare, so the program never showed the fare. A trace with a test value, such as an age of 20, would have exposed that: the trace table would have had nothing in the OUTPUT column.
Stage: Apply
Write one yourself
A school marks a test out of 50, and a mark of 25 or more is a pass.
Think it through
Write this as Cambridge pseudocode: input the mark, then output “Pass” if it is 25 or more and “Fail” otherwise. Then say, in words, how its flowchart would look: which shapes, in order.
Work this out on paper or the board first. Nothing here is marked: compare yours with the model answer.
- Hint 1: Which comparison symbol includes 25 itself?
- Hint 2: There is one input, one decision and two outputs.
Show a model answer
INPUT Mark
IF Mark >= 25
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIFThe flowchart: an oval (START); a parallelogram (INPUT Mark); a diamond (Mark >= 25 ?) with two arrows out; Yes goes to a parallelogram (OUTPUT “Pass”) and No goes to a parallelogram (OUTPUT “Fail”); both lead to an oval (STOP). The symbol must be >= and not >, or a mark of exactly 25 would fail.
Apply it
Show the answer
Answer: C. IF Age >= 12 THEN OUTPUT "Allowed" ELSE OUTPUT "Not allowed" ENDIF
The condition, and which output goes with Yes and which with No, must all match.
Go deeper The same algorithm in Python
Python is a real programming language, so a computer can run this. It follows the same idea with different notation:
age = int(input())
if age <= 15:
fare = 1
else:
fare = 2
print(fare)=stores a value in Python, where pseudocode uses ←. Python asks a question with==.- There is no
THENorENDIF: the colon (:) and the indentation show what belongs to theifand theelse. Indenting wrongly changes the meaning. input()returns text, soint(...)turns it into a whole number. Pseudocode does not need this.printis Python’s OUTPUT. Python’s keywords are lower case; pseudocode’s are capitals.
Exam papers ask for pseudocode, so practise that first. Python is for running what you have designed.
Stage: Consolidate
Show what you know
Think it through
Explain to someone new why an algorithm for an exam or for a computer should say Age > 15 rather than “age is greater than 15”, and say one thing that a flowchart does better than pseudocode and one thing that pseudocode does better.
Show a model answer
A good answer says that symbols have one meaning and sentences can be read in several ways (“older than” or “15 or older”), so the same algorithm always gives the same result. A flowchart shows the paths at a glance, so it is good for seeing the shape of a decision; pseudocode is compact and is close to real code, so it is quicker to write and to turn into a program.
Apply it
Show the answer
Answer: C. Books < 5
“Fewer than 5” is exactly < 5: it is true up to 4 and false for 5.
- An algorithm must be precise. Conditions use the symbols
=,<,<=,>,>=and<>, not everyday words, and the values on the edge of a condition (such as exactly 15) decide whether the right symbol was chosen. - A flowchart uses standard symbols: an oval for the start and stop, a parallelogram for input and output, a rectangle for a process, a diamond for a decision with two arrows labelled Yes and No, a rectangle with double sides for a subroutine, and arrows for the order.
- Pseudocode writes an algorithm in text: keywords in capitals,
←for assignment, indentation to show what belongs where, and each IF closed by ENDIF. - A trace table follows an algorithm by hand, recording what the values and the output are.
- The arrow ← stores a value; the symbol = asks a question.
Sources and scope
- What this lesson is. The second lesson of the Algorithms and Programming module, written for this site. It covers point 7.2(c) of Cambridge IGCSE Computer Science 0478 (2026 to 2028, version 6) and the precision rule of 7.9, with a first look at trace tables (7.7). Its curriculum links are provisional and imply no review or endorsement by any examination board.
- Original material. Greenway Buses, the canteen till, the pass mark, the cinema, the library and Sam are fictional, written for this lesson. The flowcharts are described in tables instead of drawn, so that they can be read by anyone and checked line by line. The pseudocode follows the layout in the syllabus’s pseudocode guide.
- Simplified on purpose. Declarations (DECLARE) and data types are left to Lesson 3; the IF statement is used here to read and write one two-way decision, and Lesson 4 teaches selection fully. The subroutine symbol is named but not used, as subroutines are outside this module’s first lessons. The shapes are described in words; real flowcharts are drawn.
A sequence of precise steps that solves a problem or completes a task.
A statement that stores a value in a variable. In Cambridge pseudocode it is written with an arrow, for example Score ← 0.
An expression that is either true or false, such as Age >= 12, used to decide what a program does next.
The kind of value a variable holds, such as a whole number or text. It decides what the program can do with the value.
A diagram of an algorithm that uses standard shapes joined by arrows to show the steps and the order they happen in.
A precise but language-independent way of writing an algorithm, with set keywords such as IF, WHILE and OUTPUT, that is not tied to any one programming language.
Choosing which instructions to carry out, depending on whether a condition is true. IF and CASE statements do this.
A table used to follow an algorithm by hand, with a column for each variable and for the output and a row for each step, to record how the values change.
A named place in memory that stores a value which can change while a program runs.
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.