REPEAT
statements
UNTIL expression
Marks the end of a REPEAT loop and performs the post-test that decides whether to loop again.
The block between REPEAT and UNTIL always runs at least once. After it runs, expression is evaluated:
- If expression is true, the loop ends and execution continues after UNTIL.
- If expression is false, control returns to the matching REPEAT.
- Note
- REPEAT…UNTIL blocks may be nested freely.
How to think about it
- Read it as “do these statements until the condition becomes true” (exit-on-true).
- If you want an entry-test loop instead, use WHILE … ENDWHILE.
Examples
Count until a limit
N = 0
REPEAT
PRINT "N = "; N
N = N + 1
UNTIL N >= 5
Prompt until a non-empty string
NAME$ = ""
REPEAT
PRINT "Enter your name:";
INPUT NAME$
UNTIL LEN(NAME$) > 0
PRINT "Hello, "; NAME$
Wait until a key is pressed
PRINT "Press any key to stop."
REPEAT
REM do some periodic work here
UNTIL INKEY$ <> ""
Nested loops
Y = 0
REPEAT
X = 0
REPEAT
PRINT "X="; X; ", Y="; Y
X = X + 1
UNTIL X = 3
Y = Y + 1
UNTIL Y = 2
Notes
- The condition after UNTIL is an ordinary boolean expression; use comparisons like =, <>, <, >, <=, >=.
- Because the test is after the body, the body runs once even if the condition is initially true.
- REPEAT…UNTIL works alongside other control structures (FOR…NEXT, IF…ENDIF, WHILE…ENDWHILE) and may be nested within them.
See also:
REPEAT · WHILE · LEN · INKEY$