10 min read
Introduction
Why programmers plan before they code, and the flowcharts and pseudocode you will learn to write and read.
Plan Before You Code
Perera Corner Mart, Starlight Cinema and their prices are made up for this unit. Any resemblance to real businesses is a coincidence.
Before writing code, programmers plan the algorithm — the exact steps. Two common ways to write an algorithm down are:
- Flowcharts — diagrams made of standard symbols joined by arrows.
- Pseudocode — structured English that looks a little like code but is not tied to any language.
A clear plan makes the code quicker to write, and mistakes are much easier to spot on paper.
A preview: the discount rule as a flowchart
Read this flowchart as text
- Terminator: Start (then → INPUT total)
- Input/output: INPUT total (then → total > 5000?)
- Decision: total > 5000? (Yes → total = total × 0.9; No → OUTPUT total)
- Process: total = total × 0.9 (then → OUTPUT total)
- Input/output: OUTPUT total (then → Stop)
- Terminator: Stop
What You Will Be Able to Do
- Describe what an algorithm is and write one in plain steps.
- Name and draw every flowchart symbol.
- Draw flowcharts for sequence, selection (including nested decisions) and loops.
- Read a flowchart, work out its output, and fill in missing symbols.
- Write the same algorithms in pseudocode.
- Trace an algorithm with a trace table to check it works.
Practice
Why draw a flowchart before writing code?
More lessons in Algorithms, Flowcharts and Pseudocode · Next: What Is an Algorithm?
