Operator For (iteration)

Declares or defines operators used by a For...Next loop with user defined type variables

{ Type | Class | Union } typename
declare operator For ()
declare operator For ( [ byref | byval ] stp as typename )
End { Type | Class | Union }

For iterator [ As typename ] = start_value To end_value [ Step step_value ]
[ ...statements... ]

name of the Type, Class, or Union
stp, step_value
a typename object used as an incremental value
a typename object used as an iterator
a typename object used as a loop-terminating value
a typename object used to copy construct or assign to the iterator initially

Operator For, Operator Next and Operator Step can be overloaded in user-defined type definitions to allow objects of that type to be used as iterators and step values in For...Next loops.
As all non-static member procedures, they have passed a hidden this parameter that allows to access by reference to the iterator object in the code body of the 3 operators.

Operator For is called immediately after copy constructing or assigning to the iterator object, and allows the object to perform any additional initialization needed in preparation for the loop.

The first version of Operator For is used if no step value is given in the For...Next statement. If a step value is given, the second version is used and is passed the step value because eventual additional initialization may use it.

See the Operator Step examples.

Dialect Differences:
See also:
Back to Iterating Operators
Back to Operators

Valid XHTML :: Valid CSS: :: Powered by WikkaWiki

sf.net phatcode