table.foreachi

From GMod Wiki

Jump to: navigation, search
Function
Syntax table.foreachi( Table t, Function f )
Where is this used?
Description:
Iterate over each numerically indexed value in t, calling f with each index and value.
Returns: nil
Part of Library: Table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.foreachi]Table.foreachi [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionPrints the keys and values of the table.
Used onNewerShared.png
Code
someTable = {"a", nonnumeric = "b", "c", "d", "e"}
function someFunction(i, v)
  print(i, v)
end
table.foreachi(someTable, someFunction)
Output1       a

2       c
3       d

4       e


Additional Notes

for i, v in ipairs(someTable) do
  someFunction(i, v)
end

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox