A while loop repeats while its condition stays true.

While Loop

while_loop.lua
local start = 
local counter = start
local total = 0

while counter > 0 do
  total = total + counter
  counter = counter - 1
end

print("start=" .. start)
print("total=" .. total)
local start = 
local counter = start
local total = 0

while counter > 0 do
  total = total + counter
  counter = counter - 1
end

print("start=" .. start)
print("total=" .. total)
local start = 
local counter = start
local total = 0

while counter > 0 do
  total = total + counter
  counter = counter - 1
end

print("start=" .. start)
print("total=" .. total)
condition first The condition is checked before each iteration, so the loop may run zero or more times.