Algorithms and loops
Years 3 to 9
An algorithm is a list of exact steps, and a loop repeats steps so you do not have to write them again and again.
For learners
An algorithm is a list of steps that solves a problem, like a recipe. A computer follows every step exactly, in order, and can't guess what you meant.
A loop repeats steps. 'Repeat 4 times: move forward 3' moves 12 squares, and you only wrote it once.
A flowchart draws an algorithm as a picture. A diamond asks a question, and the answer decides which arrow to follow.
A worked example
A program says: repeat 5 times: move forward 4. How far does it move?
- One repeat moves 4.
- There are 5 repeats.
- squares.
For grown-ups
Programming starts with breaking a job into precise steps. Try giving an adult instructions to make toast, and follow them literally: it quickly shows why every detail matters. To trace code, keep a small table with a column for each variable, and update it one line at a time.
Common mistakes
- Leaving out a step because it seems obvious.
- Repeating one time too many or too few (the 'off by one' bug).
- Not updating a variable inside the loop, so it never stops.
Why it matters
Every app and game is built from algorithms. Loops and decisions are the building blocks of almost all code.
Topics in quarter that use this
- Giving a robot precise instructions
- Loops: repeating instructions
- Tracing code
- Spotting bugs
- AND, OR and NOT