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

# 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.

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.

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.