table.foreach

From ComputerCraft
Jump to: navigation, search

table.foreach
Function
Syntax
table.foreach()
Returns nil
API table
Source Lua (source)
This function is deprecated.[1]

Calls func once for each key-value pair in the tbl. Specifically,

table.foreach(tbl, func)

is equivalent to

for key, value in pairs(tbl) do
  if func(key, value) ~= nil then
    break
  end
end
ExampleExamplePrint the elements of a table
Print out each key-value pair in tbl.
Code
local tbl = { a = 1, b = 2, 'foo', 'bar' }
table.foreach(tbl, function(k, v)
  print(k, v)
end)
Output
a 1
b 2
1 foo
2 bar

References