Codectionary / Developer documentation / Lua

Lua Conditions & Loops

Lua uses then/end for conditionals and do/end for loops. In Lua, only false and nil are falsey; zero and empty strings are truthy.

Syntax

if ready then
  print("go")
end

for i = 1, 3 do
  print(i)
end

Examples

Iterating a sequence

A small, runnable example of this syntax.

local tags = { "lua", "game", "web" }
for index, tag in ipairs(tags) do
  print(index, tag)
end

Best practices

  • Use ipairs for sequential array-like tables and pairs when you want to visit all key-value entries without ordering guarantees.
  • Keep examples small while learning, then combine the idea with a real project.

Runtime & versions

Lua interpreter or a host application. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Lua reference manuals

Specifications & further reading