{{luaapi}}
m (Robot: converting/fixing HTML) |
({{luaapi}}) |
||
| Line 1: | Line 1: | ||
{{luaapi}} | |||
Returns the next key/value pair for a given table and key. | |||
next (table, [ | key, value = next (table, [oldKey]) | ||
Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an index in this table. '''<tt>next</tt>''' returns the next index of the table and the value associated with the index. When called with nil as its second argument, '''<tt>next</tt>''' returns the first index of the table and its associated value. When called with the last index, or with nil in an empty table, '''<tt>next</tt>''' returns nil. If the second argument is absent, then it is interpreted as nil. | Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an index in this table. '''<tt>next</tt>''' returns the next index of the table and the value associated with the index. When called with nil as its second argument, '''<tt>next</tt>''' returns the first index of the table and its associated value. When called with the last index, or with nil in an empty table, '''<tt>next</tt>''' returns nil. If the second argument is absent, then it is interpreted as nil. | ||
| Line 10: | Line 10: | ||
The behavior of '''<tt>next</tt>''' is undefined if, during the traversal, you assign any value to a non-existent field in the table. Changing values of existing keys or removing keys is alright though. | The behavior of '''<tt>next</tt>''' is undefined if, during the traversal, you assign any value to a non-existent field in the table. Changing values of existing keys or removing keys is alright though. | ||