Look at this row: red, blue, red, blue, red, blue. What comes next? You knew straight away, because your brain spotted a pattern. Pattern recognition is the second pillar of computational thinking in our overview of the four pillars, and it quietly powers a huge amount of programming.
Why patterns matter in code
When a programmer notices that the same thing happens again and again, they do not write it again and again. They capture it once. Patterns lead directly to two of the most important ideas in coding:
- Loops, which repeat actions. If you notice you are doing the same steps many times, a loop is probably hiding there. See Python loops for kids.
- Functions, which package up a set of steps so you can reuse them with different details. See Python functions for kids.
A drawing example
Suppose a child wants to draw a square with the turtle. The instructions are:
forward(100)
right(90)
forward(100)
right(90)
forward(100)
right(90)
forward(100)
right(90)Ask: "What do you notice?" The pair forward(100) and right(90) appears four times. That is the pattern! Now they can say it shorter:
for i in range(4):
forward(100)
right(90)Eight lines became three. And once they see the pattern, they can try a triangle (3 times, turning 120) or a hexagon (6 times, turning 60). Pattern recognition made the next idea almost free. More about this in drawing with code.
Games that train the skill
You do not need a computer for any of these:
- What comes next? Make bead, block or clap patterns and let your child continue them. Then swap roles.
- Find the rule. Say numbers like 2, 4, 6, 8 and ask for the rule. Then try harder ones such as 1, 2, 4, 8.
- Spot the repeat. Look at a song's lyrics together. Which lines repeat? That is a chorus, which is really a function.
- Tile hunt. Look at a patterned floor or wallpaper and describe the smallest piece that repeats.
Patterns, differences and details
A useful extra step is noticing what is the same and what is different. Two songs might share a chorus but have different verses. Two games might both have a score, but one counts up and the other counts down. In code, the "same" part becomes the function and the "different" part becomes its parameters.
Where it shows up in AI
Modern AI systems are, at heart, extremely good at finding patterns in large amounts of data. If your child enjoys this topic, our explainer on what AI is for kids connects the idea.
Questions to ask
- "Have you done this before? What was the same?"
- "Could a loop do this for us?"
- "What changes each time, and what stays put?"
Those three questions can transform a long, repetitive program into a short, elegant one. The Thinking course offers short puzzles that build this habit.