The big ideaA repeat until loop keeps going until something becomes true. It checks each time round.
How it works
A repeat until loop keeps going until something becomes true.
It checks each time round, so you do not need to know the number.
A counting loop needs you to know the number. Repeat until works when you do not.
The same repeat until program works for a small jug and a huge barrel.
Two ways to stop a loop.
Example 1: Counting too far
Mina's first program says repeat 10 times: scoop a cup, pour it in.
The jug holds only 6 cups.
Cup 7 spills water across the table, because Bo never looks.
Example 2: Repeat until
Mina changes it to repeat until the jug is full.
Bo scoops, pours and looks, again and again.
At cup 6 he looks, nods and stops, and not one drop spills.
Line 4 is the check.
Example 3: A bigger barrel
Teo rolls in a barrel that takes 15 cups.
The same program, repeat until the barrel is full, still works.
It needs no new number.
Example 4: The toy train
Teo's train program says repeat 5 times, move one piece of track, but the track is 8 pieces long.
The train stops after 5 pieces, so 8 - 5 = 3 pieces are left, and it stops before the station.
The fix: repeat until at the station, which checks each time.
Words to know
repeat until
A loop that keeps going until something becomes true.
check
Looking to see if the answer is yes yet.
counting loop
A loop that repeats a set number of times.
Watch out
Counting only works when you know the number. If you do not, use repeat until.
A repeat until loop needs a check inside it, and it must be able to become true.
Do not guess the number. Let the check decide when to stop.
Do not mix them up: clapping 5 times is counted, and knocking until someone answers is a repeat until.
Try it
Is stirring paint until it is smooth a counting loop or a repeat until?
Is clapping 5 times a counting loop or a repeat until?
When does a repeat until loop check?
A track is 12 pieces and the train moves 5. How many pieces are left?
Which works for any size of jug: repeat 6 times or repeat until the jug is full?
Answers: 1. A repeat until · 2. A counting loop · 3. Every time round · 4. 7 · 5. Repeat until the jug is full
Try at homeStir something with a grown-up, like pancake batter or paint, until it is smooth. Did you count your stirs? No, you looked, and that is repeat until. Find two more things you do until something happens, like walking until you reach the door.
For grown-upsDo the Mission: stir something together, like pancake batter or paint, until it is smooth. Did you count your stirs? No, you looked. Find two more things you do until something happens, like walking until you reach the door.
Open these notes on screenScan the code, or go to tutorpip.com.