table.foreach
Calls func once for each key-value pair in the tbl. Specifically,
<nowiki>
table.foreach(tbl, func)
</nowiki>
| table.foreach Function | |
|---|---|
|
Syntax table.foreach(
| |
| Returns | nil |
| API | table |
| Source | Lua (source) |
This function is deprecated.[1]
is equivalent to
<nowiki>
for key, value in pairs(tbl) do
if func(key, value) ~= nil then
break
end
end
</nowiki>
|
|||
Print out each key-value pair in tbl. |
|||
| Code | <nowiki>
local tbl = { a = 1, b = 2, 'foo', 'bar' }
table.foreach(tbl, function(k, v)
print(k, v)
end)
</nowiki>
|
||
| Output | <nowiki>
a 1
b 2
1 foo
2 bar
</nowiki>
|
||
Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Lua |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CC:Tweaked |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
References
- "lua-users wiki: Table Library Tutorial". Retrieved 2018-08-13.
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.