MENU

COMPUTER PROGRAMMING – 9. Repetition

There are three basic building blocks to use when designing algorithms:

  • sequencing
  • selection
  • repetition

What is repetition?

Repetition is often also referred to as loops. In computer programming, repetition is the process of looping or repeating sections of a computer program.

There are different types of loop. The most basic is where a set of instructions is repeated a set number of times. Another type of loop repeats continuously until a certain condition is met.

For example, a very simple algorithm for eating breakfast cereal might consist of these steps:​​​​​​​​​​​​​​​​​​​​​​​​​​​​

cereal_bowl1_1

Repetition in practice: Cleaning teeth

A simple algorithm can be created for cleaning teeth. Suppose a person has ten top teeth. To make sure that every one of the top teeth is cleaned, the algorithm would look something like this:

toothbrush_2

Steps 2 to 11 are basically the same step repeated, just cleaning a different tooth every time.Repetiton can be used to greatly simplify the algorithm. Look at this alternative:

toothbrush1

The second algorithm is much simpler. However, we also need to include a condition for this algorithm to work.

condition is a situation that is checked every time instructions are repeated. The condition, in this case, will be to check if the number of teeth cleaned equals ten. If that condition is ‘False’ (the number of teeth cleaned is less than ten), then the instructions are repeated. If the condition is ‘True’ (the number of teeth cleaned equals ten), then there would be no more repetition.​​​​​​​​​​​​​​

Why is repetition important?

Repetition allows algorithms to be simplified by stating that certain steps will repeat until told otherwise. This makes designing algorithms quicker and simpler because they don’t need to include lots of unnecessary steps.

Repetition using Scratch

Scratch game tutorials:

It is so much fun creating games using Scratch! Practising is the best way to learn how to program.

There are many types of games you can have a go at creating. Click on the links below to go to video tutorials that talk you through some of the most popular ones:

  1. Scratch basics
  2. Pong game
  3. Shark and fish game
  4. Maze game
  5. Racing game
  6. Shooting game

Follow this hyperlink to learn more:-

  1. Hour of Code
  2. BBC Schools

Computing Home Page

Icons - Copy

 

Click here for KS2 Curriculum Dashboard (All Subjects)

 

IMPORTANT NEWS FOR PARENTS AND SUPPLIERS

 

Parents and suppliers who need to contact us please do so via email office@ske.uk.net
Please scan and attach materials where possible, as the office will be closed and any post will not immediately be opened.
Any queries for admissions should be sent to admissions@ske.uk.net
×