A REPEAT…UNTIL loop with two ways to stop

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

A REPEAT…UNTIL loop with two ways to stop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A loop ends with UNTIL Guess = Secret OR Tries = 5. The guess is wrong but Tries is 5. Does the loop stop?
A Yes, Tries = 5 is TRUE, so the whole OR condition is TRUE
B No, the guess is still wrong, so it keeps going
2. Which UNTIL line gives the guessing game two ways to stop?
A UNTIL Guess = Secret OR Tries = 5
B UNTIL Guess = Secret AND Tries = 5
3. In UNTIL Guess = Secret OR Tries = 5, Guess = Secret is TRUE and Tries is only 2. What happens?
A The loop keeps repeating until Tries reaches 5
B The loop stops, because one TRUE part is enough
4. When does a REPEAT...UNTIL loop go around again?
A While the UNTIL condition is TRUE
B While the UNTIL condition is FALSE
5. The guess is wrong and Tries = 3. What is UNTIL Guess = Secret OR Tries = 5?
A FALSE, so the loop repeats
B TRUE, so the loop stops

Match the Pairs

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

Left columnRight column
1UNTIL Guess = Secret OR Tries = 5 AREPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
2UNTIL Mark >= 0 AND Mark <= 100 BStop repeating as soon as the guess is correct or the player has used 5 tries, whichever happens first.
3A guessing game that must stop when the guess is right or the tries have run out CAND is used instead of OR. The loop only stops if the guess is correct and the fifth try is used at the same time, so a correct guess on try 2 does not end it.
4Keep asking for a mark until it is inside the valid range of 0 to 100 DStop repeating only when the mark is both at least 0 and at most 100, so the input is valid.
5UNTIL Guess = Secret AND Tries = 5 EREPEAT INPUT Guess Tries ← Tries + 1 UNTIL Guess = Secret OR Tries = 5
6UNTIL Mark >= 0 OR Mark <= 100 FOR is used instead of AND. Every number is at least 0 or at most 100, so the condition is always TRUE and invalid marks like 150 or -5 are accepted.

Definitions

UNTIL Guess = Secret OR Tries = 5

Fill in the Blanks

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

1.
REPEAT INPUT Guess UNTIL Guess = Secret __ Tries = 5
2.
REPEAT INPUT Guess _____ Guess = Secret OR Tries = 5
3.
REPEAT Tries ← Tries + 1 UNTIL Guess = Secret OR _____ = 5
4.
REPEAT INPUT Mark UNTIL Mark >= 0 ___ Mark <= 100
5.
REPEAT INPUT Mark UNTIL Mark __ 0 AND Mark <= 100

Spot the Error

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

Question 1
A Tries ← 5
B REPEAT
C INPUT Guess
D Tries ← Tries + 1
E UNTIL Guess=Secret OR Tries=5
Question 2
A Tries ← 0
B REPEAT
C Tries ← Tries
D INPUT Guess
E UNTIL Guess=Secret OR Tries=5
Question 3
A REPEAT
B INPUT Mark
C UNTIL Mark>=0 OR Mark<=100
Question 4
A REPEAT
B OUTPUT Mark
C UNTIL Mark>=0 AND Mark<=10
Question 5
A OUTPUT "Enter a mark"
B REPEAT
C INPUT Mark
D UNTIL Mark>=0 AND Mark>=100

Answer Key

A REPEAT…UNTIL loop with two ways to stop
Section A: Quick Questions
Q1
A — Yes, Tries = 5 is TRUE, so the whole OR condition is TRUE
Q2
A — UNTIL Guess = Secret OR Tries = 5
Q3
B — The loop stops, because one TRUE part is enough
Q4
B — While the UNTIL condition is FALSE
Q5
A — FALSE, so the loop repeats
Section B: Match the Pairs
Q1
UNTIL Guess = Secret OR Tries = 5 → Stop repeating as soon as the guess is correct or the player has used 5 tries, whichever happens first.
Q2
UNTIL Mark >= 0 AND Mark <= 100 → Stop repeating only when the mark is both at least 0 and at most 100, so the input is valid.
Q3
A guessing game that must stop when the guess is right or the tries have run out → REPEAT INPUT Guess Tries ← Tries + 1 UNTIL Guess = Secret OR Tries = 5
Q4
Keep asking for a mark until it is inside the valid range of 0 to 100 → REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
Q5
UNTIL Guess = Secret AND Tries = 5 → AND is used instead of OR. The loop only stops if the guess is correct and the fifth try is used at the same time, so a correct guess on try 2 does not end it.
Q6
UNTIL Mark >= 0 OR Mark <= 100 → OR is used instead of AND. Every number is at least 0 or at most 100, so the condition is always TRUE and invalid marks like 150 or -5 are accepted.
Section C: Definitions
Q1
UNTIL Guess = Secret OR Tries = 5 — A REPEAT loop whose UNTIL condition uses OR stops as soon as either part becomes TRUE, so the loop has two ways to end: a correct guess or running out of tries.
Section D: Fill in the Blanks
Q1
REPEAT INPUT Guess UNTIL Guess = Secret OR Tries = 5
Q2
REPEAT INPUT Guess UNTIL Guess = Secret OR Tries = 5
Q3
REPEAT Tries ← Tries + 1 UNTIL Guess = Secret OR Tries = 5
Q4
REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
Q5
REPEAT INPUT Mark UNTIL Mark >= 0 AND Mark <= 100
Section E: Spot the Error
Q1
A — Tries must start at 0. Starting at 5 means it becomes 6 after the first guess and never equals 5, so only a correct guess can end the loop. It should be Tries ← 0.
Q2
C — Tries never increases, so Tries = 5 can never become TRUE. The second way to stop is lost. It should be Tries ← Tries + 1.
Q3
C — Every number is at least 0 or at most 100, so OR is always TRUE and invalid marks are accepted. Validation needs AND so both parts are TRUE before the loop stops.
Q4
B — The loop never reads a new value, so Mark never changes and the UNTIL condition is never met. The line should be INPUT Mark.
Q5
D — Mark>=100 is the wrong test for the upper limit, so only marks of 100 or more would be accepted. The second part should be Mark<=100.