for i, v in ipairs() LoopsA table is like a box that stores multiple values — numbers, strings, objects, or even other tables.
Example:
lua
CopyEdit
local fruits = {"apple", "banana", "cherry"}
This is a list table with 3 values.
for i, v in ipairs() Loop?This loop lets you go through each item in a table, one by one.
lua
CopyEdit
for i, v in ipairs(table) do
-- i = index (1, 2, 3...)
-- v = value at that index
end
lua
CopyEdit
local fruits = {"apple", "banana", "cherry"}
for i, fruit in ipairs(fruits) do
print("Fruit #" .. i .. ": " .. fruit)
end
🖨️ Output:
nginx
CopyEdit
Fruit #1: apple
Fruit #2: banana
Fruit #3: cherry