m
no edit summary
(Use Lua/Libshortcut template. Change category from "LUA Functions" to "Lua functions".) |
mNo edit summary |
||
| Line 13: | Line 13: | ||
Note in the example only the indexed elements of the table are displayed. See the TablesTutorial for more information on key-value and index-value pairs. | Note in the example only the indexed elements of the table are displayed. See the TablesTutorial for more information on key-value and index-value pairs. | ||
Also note that foreachi starts at index [1], increments the index by one repeatedly, and stops running as soon as it reaches a nil value. This is an example: | |||
> t = { [0] = "zero", --will not be counted | |||
[1] = "one", --will be counted; 1 | |||
[2] = "two", --will be counted; 2 | |||
[3] = "three", --will be counted; 3 | |||
["four"] = "four", --will not be counted; returns 3 | |||
[5] = "five" } --will never be reached | |||
> foreachi(t, print) | |||
1 one | |||
2 two | |||
3 three | |||
In the above, it starts at t[1] (''not'' t[0]) and counts to t[3], printing the corresponding values along the way. It then checks t[4], sees it is nil, and stops running. t[5] is never checked - this ''will not hit every array index in a table, only the consecutive ones from one up until it hits its first blank index.'' | |||
{{LUA}} | {{LUA}} | ||