Flowcharts
The standard symbols, and turning a flowchart into code.
Covers OCR J277 2.1.2 Designing, creating and refining algorithms · AQA 8525 3.1.1 Representing algorithms · Edexcel 1CP2 1.2.1 Following and writing algorithms
Do this lesson in the simulatorPrint it: worksheet (PDF) · answers (PDF) · as a web page
A flowchart draws an algorithm. Each step is a box, arrows show the order, and a diamond shows a decision. Flowcharts are good for seeing the shape of an algorithm at a glance: where it loops, where it branches, and where it ends. Exams use them a lot, both to give you an algorithm and to ask you to draw one.
The symbols
| Symbol | Used for | Example |
|---|---|---|
| Rounded box | Start or end | Start, End |
| Rectangle | A process: do something | drive forward 5 cm, count = count + 1 |
| Diamond | A decision: a yes or no question, with two arrows out | Is the distance more than 25? |
| Slanted box | Input or output | input a password, output "arrived" |
| Box with double sides | A subroutine: a subprogram defined elsewhere | tone(note, 0.2) |
Arrows join the symbols and show which way the algorithm goes. A decision always has exactly two arrows out, labelled Yes and No.
From flowchart to code
Here is creep to the wall as a flowchart:
The arrow from the bottom back up to the decision makes a loop. A decision that an arrow loops back to becomes a while: keep going round while the answer is Yes, leave when it is No.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
while distance() > 25: # the decision
forward(50, distance=5) # the process on the Yes path
print("arrived") # the output on the No path
A decision with no loop back becomes an if. So: arrow back to an earlier decision, while; no arrow back, if.
A loop that counts
This flowchart plays a rising scale of five notes. The subroutine box is a call to tone, which is defined elsewhere, in the robot's library.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
note = 300
count = 0
while count < 5:
tone(note, 0.2)
note = note + 100
count = count + 1
print(count)
Follow the arrows with your finger and check each line matches a box. A flowchart has no for: a counting loop is drawn with a variable, a decision and an update, exactly as a while does it.
Drawing your own
To draw a flowchart for an algorithm:
- Start with a Start box and end with an End box.
- Put each action in its own rectangle, and each input or output in a slanted box.
- Every question is a diamond with a Yes arrow and a No arrow.
- For a loop, draw the arrow back to the decision that controls it.
- Check it: follow it for a real example, the way the computer would.
Task: the password guard
Turn this flowchart into a program. Ask for a password with the prompt Password?. While it is not bugbot, print wrong, beep, and ask again. When it is right, turn the LED green and drive forward 20 cm. The task types robot first, then bugbot.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
password = input("Password? ")
Challenges
- Draw a flowchart for the parking sensor from lesson F2.8.
- Draw a flowchart for an algorithm that asks for two numbers and outputs the larger.
- Change the guard so it gives up after three wrong passwords. What must be added to the flowchart?
Past paper questions on this
Real exam questions that test this, each worked through with a program you can run.
- AQA 8525 June 2025 Paper 1, Question 4: Validate a name by length until it is accepted, test data, and a username flowchart 13 marks
- AQA 8525 June 2023 Paper 1, Question 5: Trace a flowchart with a loop 3 marks
- OCR J277 June 2025 Paper 2, Question 2(a), (b): Count the passes of a flowchart loop, and describe the kinds of iteration 8 marks
- OCR J277 June 2024 Paper 2, Question 2: Complete a flowchart that decides odd or even with MOD 4 marks
- OCR J277 June 2022 Paper 2, Question 2(b): Design a flowchart that decides who gets a half-price meal 5 marks
- OCR J277 Sample Paper 2, Question 4: Usernames from a flowchart, then an algorithm for teachers and students 8 marks
- OCR J277 Sample Paper 2, Question 8(e), (g): A while loop trace table, a function that returns minutes, and a flowchart as code 14 marks
- Edexcel 1CP2 June 2024 Paper 2, Question 4: Turn a flowchart for a cafe order into Python, rounding up with math.ceil 15 marks