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.
- 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.
- Which of these makes an algorithm easier to read?
- Meaningful variable names and indentation: Other people need to understand it too.
- What does this AQA pseudocode output?
- 6: In AQA pseudocode, FOR i ← 1 TO 3 includes 3. So total is 1 + 2 + 3 = 6.
- What does this AQA pseudocode output using MOD and DIV?
- 4: 7 MOD 2 is the remainder, 1. 7 DIV 2 is 3 whole times. 1 + 3 = 4.
- What does this AQA REPEAT … UNTIL loop output?
- 27: n goes 3, 9, 27. The check is at the end of each loop: 27 > 20, so it stops.
Pseudocode and flowcharts: exam-style questions and mark schemes
Which flowchart symbol represents a decision? [1 mark]
Answer: Diamond
An algorithm sets total to 0. For each number from 1 to 4, it adds the number to total. It then outputs total. What is output? [2 marks]
- total goes 1, 3, 6, 10 (1)
- Output: 10 (1)
Describe the flowchart symbols for a terminal, a process and a decision, and what each is used for. [3 marks]
- Terminal: a rounded rectangle, for the start or end (1)
- Process: a rectangle, for an action or calculation (1)
- Decision: a diamond, for a question with Yes and No exits (1)
Write an algorithm in pseudocode that asks the user for a password and keeps asking until they enter 'secret'. It should then output 'Welcome'. [4 marks]
- Asks the user to input a password (1)
- Uses a loop that repeats while the password is not 'secret' (or until it is) (1)
- Asks for the password again inside the loop (1)
- Outputs 'Welcome' after the loop (1)
Write an algorithm, in pseudocode or a flowchart, that asks for a password, gives the user three attempts, and outputs "Access granted" or "Locked". [6 marks]
- stores the correct password (1)
- uses a counter for the number of attempts (1)
- uses a loop that stops after 3 attempts or a correct password (1)
- inputs the password inside the loop (1)
- compares the input with the correct password using IF (1)
- outputs "Access granted" when it matches (1)
- adds 1 to the counter after a wrong attempt (1)
- outputs "Locked" after 3 wrong attempts (1)
How to answer them: exam technique and command words.
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.