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?

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?

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:

SymbolMeaningTrue for a 15-year-old?
Age > 15Age is greater than 15No
Age >= 15Age is greater than or equal to 15Yes
Age < 15Age is less than 15No
Age <= 15Age is less than or equal to 15Yes
Age = 15Age is equal to 15Yes
Age <> 15Age is not equal to 15No

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

A passenger’s age is 16. Which condition is true?
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.

BoxShapeText inside the boxNext
1OvalSTARTBox 2
2ParallelogramINPUT AgeBox 3
3DiamondAge <= 15 ?Yes: box 4. No: box 5
4RectangleFare ← 1Box 6
5RectangleFare ← 2Box 6
6ParallelogramOUTPUT FareBox 7
7OvalSTOP(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?

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:

SymbolShapeWhat it means
TerminatorOval (or rounded rectangle)The START or STOP of the algorithm
Input/outputParallelogramData going in or coming out
ProcessRectangleSomething being done, such as a calculation or storing a value
DecisionDiamondA yes/no (true/false) question with two arrows out, labelled Yes and No
SubroutineRectangle with a second vertical line inside each sideA call to a separate, named part, which has its own flowchart
Flow lineArrowThe 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

How many arrows leave a decision diamond, and how are they labelled?
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.

Following the fare flowchart: one row for each passenger
Age enteredIs Age <= 15?FareOUTPUT
9
15
16
40

    Show the completed table
    Age enteredIs Age <= 15?FareOUTPUT
    9Yes11
    15Yes11
    16No22
    40No22

    The fares are in pounds.

    Check your understanding

    Why is the row for age 15 a useful one to put in the trace table?
    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 Fare

    Think 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?

    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 Age and Fare) start with a capital letter, with a capital for each new word, as in TicketPrice. 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. THEN and ELSE are indented by two spaces and the lines inside them by four. Every IF is closed by its own ENDIF.
    • 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

    Which flowchart symbol matches the line IF Age <= 15 in the pseudocode?
    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 lines and their flowchart shapes
    Pseudocode lineFlowchart shape
    INPUT Age
    IF Age <= 15
    Fare ← 2
    OUTPUT Fare

      Show the completed table
      Pseudocode lineFlowchart shape
      INPUT Ageparallelogram
      IF Age <= 15diamond
      Fare ← 2rectangle
      OUTPUT Fareparallelogram

      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
      ENDIF

      Apply it

      A pupil buys a snack costing 120 pence but has only 100 pence. What does the program output?
      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.

      The canteen till: one row for each pupil
      PriceMoneyChangeOUTPUT
      150200
      120100
      8080

        Show the completed table
        PriceMoneyChangeOUTPUT
        1502005050
        120100-20Not enough money
        808000

        Check your understanding

        In the third row the pupil has exactly the right money. Why does the program output 0 and not “Not enough money”?
        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 = 1

        Apply it

        Sam’s pseudocode has problems with its notation. Which answer lists every one of them?
        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 Fare

        Sam 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.

        Show a model answer
        INPUT Mark
        IF Mark >= 25
          THEN
            OUTPUT "Pass"
          ELSE
            OUTPUT "Fail"
        ENDIF

        The 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

        A fictional cinema’s flowchart reads: START; INPUT Age; a decision Age >= 12 ? with Yes leading to OUTPUT “Allowed” and No leading to OUTPUT “Not allowed”; STOP. Which pseudocode matches 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 THEN or ENDIF: the colon (:) and the indentation show what belongs to the if and the else. Indenting wrongly changes the meaning.
        • input() returns text, so int(...) turns it into a whole number. Pseudocode does not need this.
        • print is 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

        A fictional library lets a pupil borrow another book only when they have borrowed fewer than 5. Which condition is correct for the pseudocode, with Books holding how many they have borrowed?
        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.