Skip main navigation

£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

Find out more

Patterns and repeats

Repetition and patterns can be found everywhere in the world. Learn why this is important for computer programming.

Repetition and patterns can be found everywhere in the world all around you. In this step, you will look at some real-world examples of repetition and then think about how the concept of repetition can be used when designing a program.

Patterns can range from simple repeating patterns, like road markings of a pedestrian crossing with black and white stripes, to patterns in nature, such as the seasons. You might notice the repeating pattern of black and white keys on a piano or the repetitive structure of your favourite song.

A sequence of flags: red, yellow, blue, green, red, yellow, blue and then a final black flag with a question mark on it.

If you take a look at the flags above from left to right, you might notice the start of a repeating pattern. The pattern is red, yellow, blue, green, red, yellow, blue, so you’d probably predict that the next flag would be green, the fourth colour in the repeating pattern. By recognising this, you could predict flag colours even further along in the sequence. Every fourth flag will be green, so what would you predict the 16th and 40th flags would be?

It can be useful to represent patterns using numbers. For the flags, the pattern would look like this: 1234 123?, and you’d expect it to continue:

1234, 1234, 1234, 1234, and so on.

Each of these numbers then represents the colour of a flag — but these numbers could actually represent any sequence of items which repeats every four items.

Eight flags on a line, labelled '1,2,3,4,1,2,3,4'. The flags labelled '1' are red, the flags labelled '2' are yellow, the flags labelled '3' are blue and the flags labelled '4' are green.

Understanding the nature of repetition and patterns can help you use these concepts in programming.

Repetition in actions

Repeating patterns can also be identified in some physical actions. For example, if you were learning the steps of a dance routine, you might have to follow these instructions:

  1. Step right
  2. Step right
  3. Step left
  4. Step left
  5. Clap
  6. Turn around

Can you identify which steps are repeated? You may have noticed that you step right twice and step left twice. These instructions can be simplified to:

  1. Step right twice
  2. Step left twice
  3. Clap
  4. Turn around

These instructions will achieve the same outcome as those before.

Why is repetition important in programming?

Being able to identify patterns in everyday life can help you to identify patterns in programming. Repetition is an important concept in developing programming skills and is commonly used in algorithms to help simplify processes. Using repetition in your programs has its advantages. Firstly, you use fewer commands which makes it quicker to create a working program. Also, using fewer commands makes it easier to check for errors in your code.

What patterns can you suggest as examples of repetition in the world around you? Share your examples in the comments section.

This article is from the free online

Introduction to Programming with Scratch

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education