Name
ForEach -- iterate over all elements of a table (V5.0)
Synopsis
[v] = ForEach(table, func[, userdata])
Function
This function can be used to iterate over all elements of the table specified in the first argument. For each table element this command will call the user function specified in func. The user function will receive two arguments: The first argument will contain the index of the table element, whereas the second argument will contain the value at that index. If the user function returns a value the loop is broken, and this value is returned as the result from ForEach().

Please note that this function will traverse the whole table. If you would just like to iterate over integer indices, use the ForEachI() command instead. See ForEachI for details.

Starting with Hollywood 6.1 this function accepts an optional userdata parameter. The value you pass here will be forwarded to your callback as the third function parameter. The value can be of any type.

Inputs
table
table that should be traversed
func
user function to call for each table element
userdata
optional: user data to pass to callback function (V6.1)
Results
v
optional: return value if iteration is broken by user function (see above)
Example
t = {1, 2, 3, 4, Test$="Hello", Value=9.2}
ForEach(t, DebugPrint)
The code above dumps the contents of table 't' using ForEach().

Show TOC