REPEAT ... UNTIL

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

REPEAT ... UNTIL

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. When does a REPEAT ... UNTIL loop test its condition?
A After the body has run
B Before the body runs
2. What is the minimum number of times the body of a REPEAT ... UNTIL loop runs?
A Zero times if the condition is already TRUE
B At least once
3. A REPEAT loop ends with UNTIL Password = "Secret". When does the loop stop?
A When Password = "Secret" is FALSE
B When Password = "Secret" is TRUE
4. Which is the correct way to end a REPEAT loop?
A UNTIL Password = "Secret"
B ENDREPEAT
5. Which loop is more likely to run its body zero times?
A WHILE ... DO ... ENDWHILE
B REPEAT ... UNTIL

Match the Pairs

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

Left columnRight column
1UNTIL Password = "Secret" AREPEAT OUTPUT "Hello" UNTIL TRUE
2REPEAT INPUT Password UNTIL Password = "Secret" BThere is no ENDREPEAT keyword. The loop must end with UNTIL and a condition such as UNTIL Password = "Secret".
3A REPEAT loop tests its condition after the body, so the body always runs at least once CAsks for a password at least once, then keeps asking until the correct one is entered
4A REPEAT loop is closed by UNTIL and a condition. There is no ENDREPEAT keyword DREPEAT INPUT Number UNTIL Number > 0
5REPEAT INPUT Password ENDREPEAT EThe condition is the wrong way round. The loop stops when it is TRUE, so this stops on a wrong password. It should be UNTIL Password = "Secret".
6REPEAT INPUT Password UNTIL Password <> "Secret" FThe loop stops as soon as Password equals "Secret", because UNTIL ends the loop when its condition is TRUE

Definitions

REPEAT ... UNTIL

Fill in the Blanks

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

1.
______ INPUT Password UNTIL Password = "Secret"
2.
REPEAT INPUT Password _____ Password = "Secret"
3.
REPEAT INPUT Password UNTIL Password _ "Secret"
4.
REPEAT INPUT Password UNTIL ________ = "Secret"
5.
REPEAT _____ Password UNTIL Password = "Secret"

Spot the Error

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

Question 1
A WHILE
B OUTPUT "Enter password"
C INPUT Password
D UNTIL Password = "Secret"
Question 2
A repeat
B INPUT Guess
C Count ← Count + 1
D UNTIL Guess = 7
Question 3
A REPEAT
B INPUT Password
C ENDREPEAT
D OUTPUT "Welcome"
Question 4
A REPEAT
B INPUT Password
C UNTIL Password <> "Secret"
Question 5
A REPEAT
B Count = Count + 1
C OUTPUT Count
D UNTIL Count = 5

Answer Key

REPEAT ... UNTIL
Section A: Quick Questions
Q1
A — After the body has run
Q2
B — At least once
Q3
B — When Password = "Secret" is TRUE
Q4
A — UNTIL Password = "Secret"
Q5
A — WHILE ... DO ... ENDWHILE
Section B: Match the Pairs
Q1
UNTIL Password = "Secret" → The loop stops as soon as Password equals "Secret", because UNTIL ends the loop when its condition is TRUE
Q2
REPEAT INPUT Password UNTIL Password = "Secret" → Asks for a password at least once, then keeps asking until the correct one is entered
Q3
A REPEAT loop tests its condition after the body, so the body always runs at least once → REPEAT OUTPUT "Hello" UNTIL TRUE
Q4
A REPEAT loop is closed by UNTIL and a condition. There is no ENDREPEAT keyword → REPEAT INPUT Number UNTIL Number > 0
Q5
REPEAT INPUT Password ENDREPEAT → There is no ENDREPEAT keyword. The loop must end with UNTIL and a condition such as UNTIL Password = "Secret".
Q6
REPEAT INPUT Password UNTIL Password <> "Secret" → The condition is the wrong way round. The loop stops when it is TRUE, so this stops on a wrong password. It should be UNTIL Password = "Secret".
Section C: Definitions
Q1
REPEAT ... UNTIL — A loop that runs its statements first, then tests the condition. It stops when the condition is TRUE, so the body always runs at least once. It has no ENDREPEAT keyword.
Section D: Fill in the Blanks
Q1
REPEAT INPUT Password UNTIL Password = "Secret"
Q2
REPEAT INPUT Password UNTIL Password = "Secret"
Q3
REPEAT INPUT Password UNTIL Password = "Secret"
Q4
REPEAT INPUT Password UNTIL Password = "Secret"
Q5
REPEAT INPUT Password UNTIL Password = "Secret"
Section E: Spot the Error
Q1
A — A REPEAT loop must start with the keyword REPEAT. WHILE starts a different loop type that has no UNTIL at the end. Line 1 should be REPEAT.
Q2
A — Pseudocode keywords must be written in upper case. Line 1 should be REPEAT, not repeat.
Q3
C — REPEAT has no ENDREPEAT keyword. The loop ends with UNTIL and a condition, so line 3 should be UNTIL Password = "Secret".
Q4
C — A REPEAT loop stops when the condition is TRUE. With <> it would stop on a wrong password and keep going on the right one. It should be UNTIL Password = "Secret".
Q5
B — Assignment uses the arrow ←, not =. The = sign is for comparing values. Line 2 should be Count ← Count + 1.