REPEAT…UNTIL loop (7d)

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

REPEAT…UNTIL loop (7d)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A REPEAT…UNTIL loop checks its condition at the END of each pass. True or false?
A True
B False
2. Which loop always runs its body at least once?
A WHILE … DO … ENDWHILE
B REPEAT … UNTIL
3. A REPEAT loop stops when the UNTIL condition is…
A FALSE
B TRUE
4. Count ← 10 REPEAT Count ← Count + 1 UNTIL Count > 5 How many times does the loop body run?
A 1 time
B 0 times
5. Which is the correct way to write a loop that asks for a number until the user enters 1 to 10?
A UNTIL Num >= 1 AND Num <= 10
B UNTIL Num < 1 OR Num > 10

Match the Pairs

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

Left columnRight column
1REPEAT INPUT Guess UNTIL Guess = 7 ANum ← 50 REPEAT OUTPUT Num UNTIL Num > 10
2UNTIL Count = 10 BThe UNTIL condition can never become TRUE because Count only goes up, so the loop never stops. It needs a condition such as Count = 10.
3A REPEAT loop always runs its body at least once, because the condition is checked after the body CWHILE Num < 5 DO Num ← Num + 1 ENDWHILE
4A WHILE loop checks first and may never run, but a REPEAT loop runs once before it checks DThe stopping condition: the loop ends when Count equals 10 and repeats while it is FALSE
5REPEAT Count ← Count + 1 ENDREPEAT EREPEAT loops end with UNTIL and a condition, not ENDREPEAT. The loop needs UNTIL Count = 5 or similar.
6REPEAT Count ← Count + 1 UNTIL Count < 0 FAsks for a guess at least once and keeps asking until the guess equals 7

Definitions

REPEAT ... UNTIL condition

Fill in the Blanks

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

1.
REPEAT INPUT Guess _____ Guess = 7
2.
______ Count ← Count + 1 UNTIL Count = 5
3.
REPEAT INPUT Password UNTIL Password _ "open"
4.
REPEAT INPUT Number UNTIL Number >= 1 ___ Number <= 10
5.
REPEAT Lives ← Lives - 1 UNTIL Lives __ 0

Spot the Error

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

Question 1
A Num ← 1
B REPEAT
C Num = Num * 2
D UNTIL Num > 100
E OUTPUT Num
Question 2
A Count ← 0
B REPEAT
C INPUT Mark
D Count ← 1
E UNTIL Mark = -1
F OUTPUT Count
Question 3
A Attempts ← 0
B WHILE Code ≠ 1234 DO
C INPUT Code
D Attempts ← Attempts + 1
E UNTIL Code = 1234
Question 4
A Num ← 10
B REPEAT
C Num ← Num + 2
D UNTIL Num <= 0
E OUTPUT Num
Question 5
A DECLARE Age : INTEGER
B DO
C INPUT Age
D UNTIL Age >= 1 AND Age <= 120

Answer Key

REPEAT…UNTIL loop (7d)
Section A: Quick Questions
Q1
A — True
Q2
B — REPEAT … UNTIL
Q3
B — TRUE
Q4
A — 1 time
Q5
A — UNTIL Num >= 1 AND Num <= 10
Section B: Match the Pairs
Q1
REPEAT INPUT Guess UNTIL Guess = 7 → Asks for a guess at least once and keeps asking until the guess equals 7
Q2
UNTIL Count = 10 → The stopping condition: the loop ends when Count equals 10 and repeats while it is FALSE
Q3
A REPEAT loop always runs its body at least once, because the condition is checked after the body → Num ← 50 REPEAT OUTPUT Num UNTIL Num > 10
Q4
A WHILE loop checks first and may never run, but a REPEAT loop runs once before it checks → WHILE Num < 5 DO Num ← Num + 1 ENDWHILE
Q5
REPEAT Count ← Count + 1 ENDREPEAT → REPEAT loops end with UNTIL and a condition, not ENDREPEAT. The loop needs UNTIL Count = 5 or similar.
Q6
REPEAT Count ← Count + 1 UNTIL Count < 0 → The UNTIL condition can never become TRUE because Count only goes up, so the loop never stops. It needs a condition such as Count = 10.
Section C: Definitions
Q1
REPEAT ... UNTIL condition — A loop that runs its lines first, then checks the UNTIL condition. It stops when the condition is TRUE, so the body always runs at least once.
Section D: Fill in the Blanks
Q1
REPEAT INPUT Guess UNTIL Guess = 7
Q2
REPEAT Count ← Count + 1 UNTIL Count = 5
Q3
REPEAT INPUT Password UNTIL Password = "open"
Q4
REPEAT INPUT Number UNTIL Number >= 1 AND Number <= 10
Q5
REPEAT Lives ← Lives - 1 UNTIL Lives <= 0
Section E: Spot the Error
Q1
C — In Cambridge pseudocode, values are assigned with ←, not =. The line should be Num ← Num * 2. The = sign is used to compare values.
Q2
D — Count is reset to 1 on every pass, so it can never count more than one. The line should be Count ← Count + 1 to add one each time the loop runs.
Q3
B — A loop that ends with UNTIL must start with REPEAT. WHILE...DO belongs with ENDWHILE. The line should be just REPEAT.
Q4
C — Num goes up, so Num <= 0 never becomes TRUE and the loop never stops. The line should be Num ← Num - 2 so that Num counts down to the stopping condition.
Q5
B — DO is not the keyword that starts a post-condition loop. The loop must open with REPEAT to match the UNTIL line that closes it.