WoW:API foreach: Difference between revisions

20 bytes removed ,  25 March 2010
{{luaapi}}
(Use Lua/Libshortcut template. Change category from "LUA Functions" to "Lua functions".)
({{luaapi}})
Line 1: Line 1:
{{:Lua/Libshortcut|foreach|table.foreach}}
{{luaapi}}
Apply the function f to the elements of the table passed. On each iteration the function f is passed the key-value pair of that element in the table.
table.foreach(tab, func);
foreach(tab, func);


From [http://lua-users.org/wiki/TableLibraryTutorial TableLibraryTutorial] of lua-users.org.
From [http://lua-users.org/wiki/TableLibraryTutorial TableLibraryTutorial] of lua-users.org.
table.foreach(table, f)
Apply the function f to the elements of the table passed. On each iteration the function f is passed the key-value pair of that element in the table.


  > table.foreach({1,"two",3}, print) -- print the key-value pairs
  > table.foreach({1,"two",3}, print) -- print the key-value pairs
Line 32: Line 31:
  pi      3.14159
  pi      3.14159
  banana  yellow
  banana  yellow
{{LUA}}