FANDOM



foreach(<tTable>, <fFunction>)
Description (from LUA 4 Manual: 6.1 Basic Functions)
"Executes the given <fFunction> over all elements of <tTable>. For each element, the function is called with the index and respective value as arguments. If the function returns any non-nil value, then the loop is broken, and this value is returned as the final value of foreach. This function could be defined in Lua:"
function foreach (t, f)
	for i, v in t do
		local res = f(i, v)
		if res then return res end
	end
end
"The behavior of foreach is undefined if you change the table t during the traversal."
Example


Arguments
<tTable>: the table to traverse.
<fFunction>: the function to execute over all elements of <tTable>.
Note: do not add trailing parentheses when entering the function name.
Related Pages


Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.