AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Efficient algorithms

Week 8 · Unit 4: Be a designer · 3 lessons
3

Spot the repeats

Computing 3: Unit 4, pp. 60–78
GoalFind the steps that are repeated in an everyday task and write them once, with a “repeat” instruction.
New words
repeat · to do the same thing againrepetitive · doing the same thing again and againuntil · up to the time when something happens
Explanation

Many tasks have steps that happen again and again. Think about watering plants. We pour water on one plant, then move to the next one, and we do this for every plant. We do not need to write the same two steps ten times. We can write them once and say “Repeat steps 2 and 3 until every plant has water”. Programs do this too. Instead of copying blocks, we can use a block that repeats them. A task that repeats steps is called repetitive.

StepInstruction
1Fill the can with water
2Pour water on one plant
3Move to the next plant
4Repeat steps 2 and 3 until all plants are watered
Worked examples
StepInstruction
1Wash the potatoes
2Peel one potato
3Put it in the pot
4Repeat steps 2 and 3 until all the potatoes are peeled
5Give the pot to an adult to cook
When peeling potatoes, we peel one potato and put it in the pot, and we do this for every potato. The repeated steps are step 2, peel a potato, and step 3, put it in the pot.
whenclickedmove50stepsturn ↻90degreesrepeat4
In Scratch, the repeat block does the job. This program repeats “move 50 steps” and “turn ↻ 90 degrees” four times. The sprite starts facing right. It draws a square path and ends where it started, facing right again.
The same idea works for a song. A chorus is sung many times, but the singer writes it down once and says “repeat the chorus”.
Class activity

Find the loop (with an adult): choose a daily task that has repeated steps, such as sweeping, setting the table, peeling vegetables or stacking books. Write the steps in order. Put a star next to the steps that repeat. Rewrite the algorithm in a shorter way with “Repeat steps … until …”. Then do the task by following your algorithm.

Practice
1
Complete: 1 Pick up the broom. 2 Sweep one patch of floor. 3 Move to the next patch. 4 Repeat steps __ and __ until the room is clean.
2
A child stacks 5 bricks. The long algorithm picks up a brick and puts it on the tower, five times, which is 10 steps. Write it with a repeat.
StepInstruction
1Pick up a brick
2Put the brick on the tower
3Pick up a brick
4Put the brick on the tower
5Pick up a brick
6Put the brick on the tower
7Pick up a brick
8Put the brick on the tower
9Pick up a brick
10Put the brick on the tower
3
A sprite faces right. After the repeat block, where is it and which way does it face?
whenclickedmove20stepsturn ↻120degreesrepeat3
4
Name an everyday task with repeated steps and say which steps repeat.