WoW:API ipairs: Difference between revisions

4 bytes removed ,  15 August 2023
m
Move page script moved page API ipairs to WoW:API ipairs without leaving a redirect
No edit summary
m (Move page script moved page API ipairs to WoW:API ipairs without leaving a redirect)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Native Lua statement:
{{luaapi}}
 
Returns an iterator triple that allows the Lua for loop to iterate over the array portion of a table.
Used in loop constructs to iterate through the values of a table where the index are only numbers, or where there is no index (an array).
iteratorFunc, table, startState = ipairs(table)
 
Example:


== Example ==
  local fruits={"apple","orange","banana","kiwi"}
  local fruits={"apple","orange","banana","kiwi"}


Line 34: Line 33:


Note that t[0] is never reached because it starts counting at [1], t["four"] is never reached because it is not an array index, and t[5] is never reached because the iterator ceases when it checks t[4] and finds a nil value.
Note that t[0] is never reached because it starts counting at [1], t["four"] is never reached because it is not an array index, and t[5] is never reached because the iterator ceases when it checks t[4] and finds a nil value.
{{LUA}}
Anonymous user