ipairs()

Type Function
Library (globals)
Return value (varies)
Revision 2017.3060
Keywords pairs, tables, next, loops, iteration
See also pairs()
next()

Overview

This function returns three values: an iteration Function, a Table, and 0. For example, the following construction will iterate over the pairs (1,t[1]), (2,t[2]), ..., up to the first integer key absent from the table.

for i,v in ipairs( t ) do
    --code
end

Syntax

ipairs( t )
t (required)

Table. The table that is to be iterated.

Example

local t = { "every", "word", "is", "on", "a", "separate", "line." }
for i,v in ipairs(t) do
   print( v )  -- print each array element on a separate line
end