Concept Flow - Until loop
Initialize variable
Check condition
EXIT
Update variable
↩Back to Check
The until loop runs the code inside it until the condition becomes true. It checks the condition first, and if false, runs the loop body.
i = 0 until i > 3 puts i i += 1 end
| Step | i | Condition (i > 3) | Condition Result | Action | Output |
|---|---|---|---|---|---|
| 1 | 0 | 0 > 3 | False | Print i=0, i = i + 1 | 0 |
| 2 | 1 | 1 > 3 | False | Print i=1, i = i + 1 | 1 |
| 3 | 2 | 2 > 3 | False | Print i=2, i = i + 1 | 2 |
| 4 | 3 | 3 > 3 | False | Print i=3, i = i + 1 | 3 |
| 5 | 4 | 4 > 3 | True | Exit loop |
| Variable | Start | After 1 | After 2 | After 3 | After 4 | Final |
|---|---|---|---|---|---|---|
| i | 0 | 1 | 2 | 3 | 4 | 4 |
Ruby until loop syntax: until condition # code runs while condition is false end It checks condition first. Runs loop body only if condition is false. Stops when condition becomes true.