Pseudocode
- Pseudocode is a way of writing an algorithm that looks like code but is not a real programming language. It lets you plan without worrying about exact syntax.
- Exam boards use their own styles: AQA has its own pseudocode, OCR uses its Exam Reference Language, and Edexcel uses Python. You can usually answer in pseudocode or in a high-level language such as Python, as long as your steps are clear.
Flowchart symbols
- Terminal (rounded rectangle): start and stop. Input/output (parallelogram). Process (rectangle): an action or calculation.
- Decision (diamond): a question with two exits, Yes and No. Subroutine (rectangle with double lines at the sides): a call to another part of the program.
- Arrows (flow lines) show the order. An arrow going back to an earlier step makes a loop.
Reading an algorithm
- Work through it one step at a time and keep track of every variable, for example in a trace table.
- An algorithm sets count to 0. While count is less than 3, it outputs count and adds 1. It outputs 0, 1 and 2, then stops because count is 3.
Writing clear algorithms
- Use meaningful variable names, indent the code inside loops and IF statements, and add comments to explain tricky parts.
Key terms
- Pseudocode
- A way of writing an algorithm that looks like code but isn't a real programming language.
- Flowchart
- A diagram that shows the steps of an algorithm using standard symbols.
- Terminal
- The rounded rectangle that shows the start or end of a flowchart.
- Process
- The rectangle used for an action or calculation.
- Decision
- The diamond used for a question with Yes and No exits.
- Input/output
- The parallelogram used when data goes in or comes out.
Quick questions on Pseudocode and flowcharts
- Which flowchart symbol is used for a decision?
- A diamond: A decision has two exits: Yes and No.
- Which flowchart symbol is used for input and output?
- A parallelogram: For example, 'INPUT name' or 'OUTPUT total'.
- Which flowchart symbol shows the start or the end?
- A rounded rectangle (terminal): Every flowchart begins and ends with a terminal.
- Which flowchart symbol is used for a process, such as a calculation?
- A rectangle: For example, 'total = total + 1'.
- What is pseudocode?
- A way of writing algorithms that looks like code but isn't a real language: It is for people, not computers.
- Why do programmers use pseudocode?
- To plan an algorithm without worrying about exact syntax: The plan can then be turned into any language.
- How many exits does a decision symbol usually have?
- Two (Yes and No): The path depends on the answer.
- An algorithm sets count to 0. While count is less than 3, it outputs count and then adds 1 to count. What is output?
- 0, 1, 2: When count reaches 3, the loop stops before outputting it.
Pseudocode and flowcharts: questions and answers
- How is a loop shown in a flowchart?
- An arrow going back to an earlier step. The flow repeats until a decision sends it on.
- What does a rectangle with double lines at the sides show in a flowchart?
- A subroutine. It calls a separate part of the program.
- x is set to 5. y is set to x × 2. Then x is set to y − 3. What is x now?
- 7. y = 10, so x = 10 − 3.