Lesson 14 of 55
8 mins readPython Repeat-Until Loops (Post-Condition)
In Plain English
`repeat ... until condition` is Lua post-test loop. It always executes the body at least once and stops as soon as the condition evaluates to true.
Deep Dive: How It Works
Post-Test Condition: Guaranteed to execute body at least once.
Terminates on True: Unlike `while` (which loops while true), `repeat ... until` loops while false and exits on true.
Scoping Perk: Local variables declared inside the `repeat` body remain visible in the `until condition` expression.
Core Rules to Remember

Loops Until True: Exits when the `until` condition evaluates to true.

Body Scope in until: Variables declared inside `repeat` can be checked directly in `until`.
Live Interactive Example
Hit Run Code to see it liveRepeat-Until Loop with Scoped Variables
Python 3.12
1
2
3
4
5
6
7
Output Console
Click "Run Code" to view the rendered output.
How it works: is_ready was declared inside repeat and inspected directly in the until condition.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Count Up with repeat-until
Declare `local i = 1`.
Use `repeat print("Num: " .. i) i = i + 1 until i > 3`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.