Wait - That Bit Repeats

A free sample lesson from Thinking Like a Coder

The idea

A runner going round and round the same lap of a track, with a counter ticking up one each lap instead of a whole new track being built for every lap.

What it actually is

Pattern recognition means noticing that something in your plan happens again and again with only a tiny change each time. Once you spot it, you stop writing the same thing over and over and say it once instead: 'do this 5 times'. Coders call that a loop. The hard part is never the loop itself - it's noticing that you're repeating yourself in the first place. That noticing is the skill.

A worked example

Repeating:  jump, jump, jump, jump, jump
Spotted:    do this 5 times: jump

Both do the same thing. The second one is shorter, easier to read, and - the big one - if you want 50 jumps you change one number instead of typing 45 more lines.

Mistakes children actually make

  1. Not noticing at all, and happily copying the same line twenty times. It works, but change one thing and you have twenty edits.
  2. Thinking it's not a pattern because a little bit changes each time - 'clap once, clap twice, clap three times' still repeats; it's the number that's counting up.

Then they try it

In the app this lesson continues with the animated explanation, spoken aloud, and then the practice: Tap the card that has a repeating pattern in it - the one where a coder would stop and reach for a loop. The editor runs your child’s real code and checks the result, with their coding buddy reacting to what they wrote.

Try it free