The repeat until block

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

The repeat until block

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. When does a 'repeat until' block stop running the blocks inside it?
A When its condition becomes true
B When its condition becomes false
2. Which block would keep a sprite walking until it touches the edge?
A repeat until <touching edge?> (move 10 steps)
B repeat 10 (touching edge?)
3. When does the program check the condition in a 'repeat until' block?
A Each time before the loop runs the blocks again
B Only once at the very start
4. A game has 'repeat until <score = 10>' with nothing inside that changes the score. What will happen?
A It stops straight away
B It never stops, because the condition never becomes true
5. Which loop will stop?
A repeat until <score = 3> (say Hello for 1 seconds)
B repeat until <score = 3> (change score by 1)

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1repeat until <score = 10> Arepeat until <answer = 7> ask [What is 3 + 4?]
2repeat until <touching edge?> Brepeat until <lives = 0> change lives by -1
3To avoid an endless loop, something inside the loop must change so the condition can become true CCount goes down (0, -1, -2...) and moves away from 5, so the condition never becomes true.
4The condition is checked each time before the blocks inside run again DNothing inside the loop changes count, so count = 5 never becomes true and the loop never ends.
5set count to 0 repeat until <count = 5> move 10 steps EKeeps running the blocks inside until the score becomes 10, then stops
6set count to 0 repeat until <count = 5> change count by -1 FKeeps repeating the blocks inside until the sprite touches the edge of the stage

Definitions

repeat until <condition>

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
____________ <(steps) = 10> move (5) steps end
2.
repeat until <(score) _ 9> change [score] by 2 end
3.
repeat until <(lives) = 0> change [_____] by -1 end
4.
repeat until <(count) = 5> ______ [count] by 1 end
5.
repeat until <(______) = [yes]> ask [Ready?] and wait end

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A set score to 0
B repeat <score = 3>
C change score by 1
D say score for 1 seconds
Question 2
A set steps to 0
B repeat until <steps = 5>
C change steps by 0
D say I took 5 steps!
Question 3
A set lives to 3
B repeat until <lives > 0>
C change lives by -1
D say lives for 1 seconds
Question 4
A repeat until <not touching edge?>
B move 5 steps
C end
D say I hit the edge!
Question 5
A set count to 0
B repeat until <count = 10>
C say count for 0.5 seconds
D set count to 0
E say Finished!

Answer Key

The repeat until block
Section A: Quick Questions
Q1
A — When its condition becomes true
Q2
A — repeat until <touching edge?> (move 10 steps)
Q3
A — Each time before the loop runs the blocks again
Q4
B — It never stops, because the condition never becomes true
Q5
B — repeat until <score = 3> (change score by 1)
Section B: Match the Pairs
Q1
repeat until <score = 10> → Keeps running the blocks inside until the score becomes 10, then stops
Q2
repeat until <touching edge?> → Keeps repeating the blocks inside until the sprite touches the edge of the stage
Q3
To avoid an endless loop, something inside the loop must change so the condition can become true → repeat until <lives = 0> change lives by -1
Q4
The condition is checked each time before the blocks inside run again → repeat until <answer = 7> ask [What is 3 + 4?]
Q5
set count to 0 repeat until <count = 5> move 10 steps → Nothing inside the loop changes count, so count = 5 never becomes true and the loop never ends.
Q6
set count to 0 repeat until <count = 5> change count by -1 → Count goes down (0, -1, -2...) and moves away from 5, so the condition never becomes true.
Section C: Definitions
Q1
repeat until <condition> — A loop block that keeps running the blocks inside it again and again, checking the condition each time, and stops only when the condition becomes true.
Section D: Fill in the Blanks
Q1
repeat until <(steps) = 10> move (5) steps end
Q2
repeat until <(score) > 9> change [score] by 2 end
Q3
repeat until <(lives) = 0> change [lives] by -1 end
Q4
repeat until <(count) = 5> change [count] by 1 end
Q5
repeat until <(answer) = [yes]> ask [Ready?] and wait end
Section E: Spot the Error
Q1
B — A plain repeat block needs a number of times, not a condition. To keep looping and check the condition each time, the line should be: repeat until <score = 3>.
Q2
C — Changing steps by 0 means steps never gets closer to 5, so the condition never becomes true and the loop is endless. It should be: change steps by 1.
Q3
B — Lives starts at 3, so lives > 0 is already true and the loop would never run. The loop should stop when lives reaches 0: repeat until <lives = 0>.
Q4
A — The sprite is not touching the edge at the start, so this condition is true straight away and the loop stops before it moves. It should be: repeat until <touching edge?>.
Q5
D — Setting count to 0 inside the loop resets it every time, so it never reaches 10 and the loop never ends. It should be: change count by 1.