Main Content

repeat until in Lua - a one or more rather than a zero or more loop

Archive - Originally posted on "The Horse's Mouth" - 2015-11-05 19:18:56 - Graham Ellis

The "repeat until" structure in Lua provides a loop with condition checking at the end - in other words, it's a "one or more times" loop, unlike while which is a "zero or more times" loop.

Syntax - straightforward; example:

  repeat
    io.write("How many people? ")
    said = tonumber(io.read())
  until said


note - no do, no then and no end. Sample program [here].