What is repetition? - Barefoot Computing

What is repetition?
Repetition is the recurrence of actions or events. For example, we eat our lunch
each lunchtime and might watch a favorite soap every evening.
Repetition in programming means to repeat the execution of certain instructions.
This can make a long sequence of instructions much shorter, and typically easier
to understand.
Using repetition in programming usually involves spotting that some of the instructions you want the computer to follow are the same, or very similar, and therefore
draws on the computational thinking process of pattern recognition / generalisation.
You’ll sometimes hear the repeating block of code referred to as a loop, i.e. the
computer keeps looping through the commands one at a time as they’re executed
(carried out).
Think about the Bee-Bot program for a square (forward, left, forward, left, forward,
left, forward, left). Notice how for each side we move forward and then turn left.
On a Roamer-Too or a Pro-Bot, you could use the repeat command to simplify the
coding for this by using the built in repeat command, replacing this code with, for
example, repeat 4 [forward, left].
The same would apply in Logo, from which the Roamer-Too and Pro-Bot programming device specific languages are derived.
Barefoot Computing - Repetition
page 1/5
Compare the 2 blocks of code above. Both programs draw equilateral triangles. Using repetition reduces the amount of typing and makes the program reflect
the underlying algorithm more clearly.
In the examples above, the repeated code is run a fixed number of times, which
is the best way to introduce the idea. You can also repeat code forever. This can
be useful in real world systems, such as a control program for a digital thermostat,
which would continually check the temperature of a room, sending a signal to turn
the heating on when this dropped below a certain value. This is a common technique in game programming. For example, the following Scratch code would make
a sprite continually chase another around the screen:
.Repetition can be combined with selection, so that a repeating block of code is run
as many times as necessary until a certain condition is met, as in this fragment in
Scratch:
You can nest one repeating block inside another. The ‘crystal flower’ programs in
Logo use this idea. For example the code below draws the flower:
Barefoot Computing - Repetition
page 2/5
Why is repetition important?
Many programs employ repetition: in a quiz we may wish to ask a player a set
number of questions; in a game we may wish for objects to continuously hide and
reappear; and a program for an air conditioning unit will keep blowing out cold air
until a desired room temperature is met for example.
Employing repetition enables us to create programs which can be easier to alter
if required, as the repeated code needs to be altered only once. For example, the
screenshots below show two programs used to draw a triangle in Scratch, one of
which employs a count-controlled loop. By using this loop command we need only
alter one value (circled), as opposed to three, in order to alter the size of the square
which the programs draws. Indeed this program can quickly be modified to draw an
entirely different regular polygon by simply changing the number of times the program is set to repeat and the angle through which the sprite should rotate.
What does repetiton look like in the
primary curriculum?
EYFS
Pupils can be introduced to the repetition in the world around them. They notice
things that always repeat such as the cycle of day and night. Things that repeat
sometimes such as coming to school Monday through Friday. The school day
itself has a repeating pattern as pupil have their play times, lunch and snack at
the same time each day. Pupils learn routines in school, such as how to hang up
their coat, line up nicely, follow the golden rules, they repeat these routines on a
daily basis. Many nursery rhymes and education songs have repeating phrases or
verses and as pupils learn to count beyond 10 they may recognise the repetition in
digits.
Barefoot Computing - Repetition
page 3/5
KS1
Pupils continue to recognise repetition in the world around them and across the
curriculum. For example, pupils may notice the continued repetition of numerals
in the decimal number system as they count to larger numbers helping them learn
about place value. They may see that numerals repeat on a number square helping them to spot patterns and create rules on how to work out 10 more or 10 less
than a number. They learn that multiplication is repeated addition. They are asked
to spot repetition of events in stories or the repetition across story structures, such
as there always being a problem. In music they learn to repeat simple phrases, in
PE they repeat actions, in science they repeat experiments on different materials.
When designing algorithms pupils may instinctively incorporate repetition based
commands without explicitly stating this for example when writing the algorithm for
making a jam sandwich they might say ‘Spread the butter on the bread’ meaning to
keep spreading the butter until the butter covers the slice. As teachers we can start
to model a more precise use of language to introduce the concept of repetition.
Pupils experience of repetition within computing lessons is likely to be limited,
since the focus at this age is on developing an understanding of sequence. Simple
programmable devices such as the Bee Bot do not offer repetition functions. However digital devices such as the Roamer®, Pro-Bot and BigTrack have count controlled repeats that pupils can explore. Pupils may also have the opportunity to use
simple graphical programming languages such as Daisy the Dinosaur and Scratch
Junior which also include count-controlled loop commands, as shown below.
KS2
Use repetition in programs
Pupils should have the opportunity to design, write and debug programs that use
repetition to accomplish specific goals. Ideally this should be across different programming languages. In doing so they will have to design the algorithms for these
programs indicating how and where repetition will be used.
Pupils may first have the opportunity to tinker with repetition commands to develop
their understanding of how these work and the similarities and differences between
different loop types. When designing their algorithms or writing their code, pupils
should have experience of looking for steps or commands that are repeated and
identifying the opportunities to use a loop and work out what form of loop is most
suitable. For example, the screenshot below left show the use of a condition controlled loop and forever loop to create a simple stopwatch in Scratch that counts up
in seconds and minutes, whilst the screenshot right shows the use of count controlled loops to draw out patterns.
Barefoot Computing - Repetition
page 4/5
Find out more about repetition
Quickstart Computing: A CPD toolkit
Wikipedia article on loops in programming
Resources by Phil Bagge explaining count-controlled loop
Resources by Phil Bagge explaining forever loops
Scratch wiki explaining: forever loop;count-controlled loop;conditional loop
Barefoot Computing - Repetition
page 5/5