Operator Step (Iteration)
 
Increments the iterator of a For...Next loop

Syntax

{ Type | Class | Union } typename
Declare Operator Step ()
Declare Operator Step ( [ ByRef | ByVal ] stp As typename )
...
End { Type | Class | Union }

Usage

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

Parameters

typename
name of the Type, Class, or Union
stp, step_value
a typename object used as an incremental value
iterator
a typename object used as an iterator
end_value
a typename object used as a loop-terminating value
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 Step is called to increment the iterator immediately after all statements in the For...Next body are executed, if any.

The first version of Operator Step 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

  • Only available in the -lang fb dialect.

See also