Name
Pairs -- traverse over all fields of a table (V2.0)
Synopsis
func, state, val = Pairs(table)
Function
This function can be used in conjunction with the generic For statement to traverse over all fields of a table. As required by the generic For statement, Pairs() will return three values: An iterator function, a private state information, and an initial value for the traversal. The iterator function will then return the key/value combination of all table fields.

If you want to traverse over the integer indices of a table only, use the IPairs() function instead.

See Generic For statement for details.

Inputs
table
table to traverse
Results
func
iterator function
state
private state information
val
initial traversal value
Example
a = {"one", "two", "three", x = 5, y = 6}
For i, v In Pairs(a)
  DebugPrint(i, v)
Next
The code above will print "0 one", "1 two", "2 three", "x 5", and "y 6".

Show TOC