Algorithms and debugging
Computer Science · Key Stage 2 · The School
Recipes for machines
An ALGORITHM is a precise, ordered list of steps that solves a problem — a recipe a machine could follow. "Draw a square: repeat 4 times [move forward 100, turn right 90°]." Precise means no gaps and no guesswork: every step exact, every order deliberate.
Predict, then run
Good programmers read an algorithm and predict its result BEFORE running it. What does "repeat 3 times [forward 100, turn right 120°]" draw? Walk it in your head: three sides, three 120° turns — a triangle. Predicting first turns surprises into lessons.
Bugs and debugging
A BUG is a mistake in the algorithm; DEBUGGING is hunting it down. The method: run the steps one at a time and watch for the first moment reality differs from your prediction — the bug lives at that step. "Repeat 4 [forward 100, turn right 80°]" fails to close the square: 80 should be 90. Found by stepping, not by staring.
Task: find the largest number in a list. ALGORITHM, in English first: (1) call the first number the biggest so far, (2) look at each remaining number in turn, (3) if it is bigger than the biggest so far, make it the new biggest, (4) at the end, the biggest so far is the answer. Trace it by hand on 4, 9, 2, 7: biggest becomes 4, then 9, then stays 9, then stays 9. Now write the code — and the hard part is already done.