Determines if a
For...Next loop should be terminated
Syntax
Usage
For iterator [ As typename ] = start_value To end_value [ Step step_value ]
[ ...statements... ]
Next
Parameters
typename
cond,
end_value
a typename object used as a loop-terminating value
stp,
step_value
a typename object used as an incremental value
iterator
a typename object used as an iterator
start_value
a typename object used to copy construct or assign to the iterator initially
Description
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.
Operator Next is called every time the iterator needs to be checked against the end value. This happens immediately after the call to its
Operator For, and immediately after any calls to its
Operator Step.
Operator Next should return zero (0) if the loop should be terminated, or non-zero if the loop should continue iterating. The first time
Operator Next is called, no statements in the
For...Next body, if any, have been executed yet.
The first version of
Operator Next 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.
Example
'' Example Type
Type T
value As Double
Declare Constructor( ByVal x As Double = 0 )
Declare Operator += ( ByVal x As Double )
Declare Operator For( ByRef stp As T )
Declare Operator Step( ByRef stp As T )
Declare Operator Next( ByRef cond As T, ByRef stp As T ) As Integer
Declare Operator Cast() As String
End Type
Constructor T ( ByVal x As Double )
value = x
End Constructor
Operator <= ( ByRef lhs As T, ByRef rhs As T ) As Integer
Operator = ( lhs.value <= rhs.value )
End Operator
Operator >= ( ByRef lhs As T, ByRef rhs As T ) As Integer
Operator = ( lhs.value >= rhs.value )
End Operator
Operator T.+= ( ByVal x As Double )
value += x
End Operator
Operator T.for( ByRef stp As T )
End Operator
Operator T.step( ByRef stp As T )
This += stp.value
End Operator
Operator T.next( ByRef cond As T, ByRef stp As T ) As Integer
If( stp.value < 0 ) Then
Operator = ( This >= cond )
Else
Operator = ( This <= cond )
End If
End Operator
Operator T.cast() As String
Operator = Str( value )
End Operator
'' Example Usage
For i As T = 10 To 1 Step -1
Print i
Next i
Dialect Differences
See also