table.foreach

From GMod Wiki

Jump to: navigation, search
Function
Syntax table.foreach( Table t, Function f )
Where is this used?
Description:
Iterate over each pair in t, calling f with the key and value of the pair.
Returns: nil
Part of Library: Table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.foreach]Table.foreach [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 = 1, b = 2, c = 3}
function someFunction(k, v)
  print(k, v)
end
table.foreach(someTable, someFunction)
Outputa       1

b       2

c       3


Additional Notes

for k, v in pairs(someTable) do
  someFunction(k, v)
end

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox