Syntax
if ready then
print("go")
end
for i = 1, 3 do
print(i)
endExamples
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)
endBest 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.
At a glance
- Purpose
- Lightweight scripting and embedding
- File extension
- .lua
- Runs in
- Lua interpreter or a host application
- Usually used with
- Host APIs and Lua modules