Enumerator Object

An enumerator is a type of function object which is called repeatedly to enumerate a sequence of values.

Enumerators exist primarily to support For-loops, and are not usually called directly. The for-loop documentation details the process by which an enumerator is called. The script may implement an enumerator to control which values are assigned to the for-loop's variables on each iteration of the loop.

Built-in enumerators are instances of the Enumerator class (which is derived from Func), but any function object can potentially be used with a for-loop.

Related: For-loop, OwnProps, __Enum (Array), __Enum (Map)

Call

Retrieves the next item or items in an enumeration.

Enum.Call(&OutputVar1 , &OutputVar2)
EnumFunction(&OutputVar1 , &OutputVar2)
OutputVar1, OutputVar2

Type: VarRef

One or more references to variables for the enumerator to assign values.

Return Value

A non-zero integer if successful or zero if there were no items remaining.

A simple function definition can be used to create an enumerator; in that case, the Call method is implied.

When defining your own enumerator, the number of parameters should match the number of variables expected to be passed to the for-loop (before the "in" keyword). This is usually either 1 or 2, but a for-loop can accept up to 19 variables. To allow the method to accept a varying number of variables, declare optional parameters.

An exception is thrown when the for-loop attempts to call the method if there are more variables than parameters (too many parameters passed, too few defined) or fewer variables than mandatory parameters.