Using a count to stop a loop

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

Using a count to stop a loop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which loop stops when the counter reaches 5?
A REPEAT UNTIL count = 5
B REPEAT UNTIL count = 0 (when count starts at 1 and goes up)
2. A game ends after 3 wrong answers. Which condition should the loop use?
A REPEAT UNTIL wrong = 3
B REPEAT UNTIL wrong = 30
3. Inside the loop, what must happen to the counter so the loop can stop?
A The counter can stay the same, because the loop will stop by itself
B The counter must change, for example count ← count + 1
4. Which set of steps will stop? A: count ← 0, REPEAT UNTIL count = 5: say 'Go!' B: count ← 0, REPEAT UNTIL count = 5: say 'Go!', count ← count + 1
A A
B B
5. A game ends at 5 points. Each right answer adds 1 point. Which step belongs inside the loop?
A points ← points + 1 (after a right answer)
B points ← 0 (every time round the loop)

Match the Pairs

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

Left columnRight column
1REPEAT UNTIL count = 3 AREPEAT UNTIL points = 5
2count ← count + 1 BKeep repeating the steps until the counter reaches 3, for example when the player has had 3 wrong answers
3A game ends when the player reaches 5 points, so the loop stops once the score counter equals 5 CThe counter goes up every time, even when the answer is right. It should only add 1 to wrong when the answer is wrong, using an IF.
4The counter is changed inside the loop so it can reach the stopping number DAdd 1 to the counter each time round, so the loop moves closer to its stopping number
5count ← 0 REPEAT UNTIL count = 3 SAY "Try again" EREPEAT UNTIL count = 5 SAY "Go!" count ← count + 1
6REPEAT UNTIL wrong = 3 ASK question wrong ← wrong + 1 FThe counter never changes inside the loop, so count stays at 0 and the loop never stops. Add count ← count + 1 inside the loop.

Definitions

REPEAT UNTIL count = 5

Fill in the Blanks

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

1.
SET count TO 0 REPEAT UNTIL _____ = 5 SET count TO count + 1
2.
SET wrong TO 0 REPEAT _____ wrong = 3 IF answer is wrong, ADD 1 to wrong
3.
SET points TO 0 REPEAT UNTIL points _ 5 SET points TO points + 1
4.
SET count TO 0 REPEAT UNTIL count = 5 SET count TO count _ 1
5.
SET wrong TO _ REPEAT UNTIL wrong = 3 IF answer is wrong, ADD 1 to wrong

Spot the Error

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

Question 1
A SET count ← 0
B REPEAT UNTIL count = 0
C SAY "Jump!"
D SET count ← count + 1
Question 2
A SET wrong ← 0
B REPEAT UNTIL wrong = 3
C ASK "What is 4 x 2?"
D IF answer = 8 THEN
E SET wrong ← wrong + 1
F SAY "Game over"
Question 3
A SET points ← 0
B REPEAT UNTIL points = 5
C SET points ← 1
D SAY points
Question 4
A SET count ← 10
B REPEAT UNTIL count = 4
C SAY "Clap"
D SET count ← count + 1
Question 5
A SET tries ← 0
B REPEAT UNTIL tries = 3
C ASK "Guess the number"
D SET tries ← tries - 1
E SAY "Out of tries"

Answer Key

Using a count to stop a loop
Section A: Quick Questions
Q1
A — REPEAT UNTIL count = 5
Q2
A — REPEAT UNTIL wrong = 3
Q3
B — The counter must change, for example count ← count + 1
Q4
B — B
Q5
A — points ← points + 1 (after a right answer)
Section B: Match the Pairs
Q1
REPEAT UNTIL count = 3 → Keep repeating the steps until the counter reaches 3, for example when the player has had 3 wrong answers
Q2
count ← count + 1 → Add 1 to the counter each time round, so the loop moves closer to its stopping number
Q3
A game ends when the player reaches 5 points, so the loop stops once the score counter equals 5 → REPEAT UNTIL points = 5
Q4
The counter is changed inside the loop so it can reach the stopping number → REPEAT UNTIL count = 5 SAY "Go!" count ← count + 1
Q5
count ← 0 REPEAT UNTIL count = 3 SAY "Try again" → The counter never changes inside the loop, so count stays at 0 and the loop never stops. Add count ← count + 1 inside the loop.
Q6
REPEAT UNTIL wrong = 3 ASK question wrong ← wrong + 1 → The counter goes up every time, even when the answer is right. It should only add 1 to wrong when the answer is wrong, using an IF.
Section C: Definitions
Q1
REPEAT UNTIL count = 5 — A loop that keeps repeating its steps until the counter reaches the chosen number, 5. The counter must change inside the loop, or the loop never stops.
Section D: Fill in the Blanks
Q1
SET count TO 0 REPEAT UNTIL count = 5 SET count TO count + 1
Q2
SET wrong TO 0 REPEAT UNTIL wrong = 3 IF answer is wrong, ADD 1 to wrong
Q3
SET points TO 0 REPEAT UNTIL points = 5 SET points TO points + 1
Q4
SET count TO 0 REPEAT UNTIL count = 5 SET count TO count + 1
Q5
SET wrong TO 0 REPEAT UNTIL wrong = 3 IF answer is wrong, ADD 1 to wrong
Section E: Spot the Error
Q1
B — The count starts at 0, so the loop would stop straight away and never jump. The line should say REPEAT UNTIL count = 5.
Q2
D — This adds 1 to wrong when the answer is correct. It should be IF answer ≠ 8 THEN so that only wrong answers are counted.
Q3
C — This puts points back to 1 every time round the loop, so it never reaches 5. It should be SET points ← points + 1.
Q4
A — The count starts at 10 and only goes up, so it can never equal 4 and the loop never stops. It should start with SET count ← 0.
Q5
D — Taking 1 away makes tries go further from 3, so the loop never stops. It should be SET tries ← tries + 1.