Revision history for KeyPgOpNext
Revision [21584]
Last edited on 2016-09-02 04:27:52 by fxm [Added explanation on why the step value is passed as parameter]Additions:
##**Operator Next**## is called every time the iterator object needs to be checked against the end value. This happens immediately after the call to its ##[[KeyPgOpFor|Operator For]]##, and immediately after any calls to its ##[[KeyPgOpStep|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 ##[[KeyPgFornext|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 ##[[KeyPgFornext|For...Next]]## statement. If a step value is given, the second version is used and is passed the step value because testing for iterating end may depend on it.
The first version of ##**Operator Next**## is used if no step value is given in the ##[[KeyPgFornext|For...Next]]## statement. If a step value is given, the second version is used and is passed the step value because testing for iterating end may depend on it.
Deletions:
The first version of ##**Operator Next**## is used if no step value is given in the ##[[KeyPgFornext|For...Next]]## statement. If a step value is given, the second version is used and is passed the step value.
Revision [21581]
Edited on 2016-09-01 16:20:18 by fxm [Added explanation on what represents the hidden parameter THIS in the code body of the operators FOR, STEP and NEXT]Additions:
As all non-static member procedures, they have passed a hidden ##[[KeyPgThis|this]]## parameter that allows to access by reference to the iterator object in the code body of the 3 operators.
Additions:
Additions:
Determines if a ##[[KeyPgFornext|For...Next]]## loop should be terminated
{ [[KeyPgType|Type]] | [[KeyPgClass|Class]] | [[KeyPgUnion|Union]] } //typename//
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **Next** ( [ [[KeyPgByref|byref]] | [[KeyPgByval|byval]] ] //cond// [[KeyPgAs|as]] //typename// ) [[KeyPgAs|as]] [[KeyPgInteger|Integer]]
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **Next** ( [ [[KeyPgByref|byref]] | [[KeyPgByval|byval]] ] //cond// [[KeyPgAs|as]] //typename//, [ [[KeyPgByref|byref]] | [[KeyPgByval|byval]] ] //stp// [[KeyPgAs|as]] //typename// ) [[KeyPgAs|as]] [[KeyPgInteger|Integer]]
End { [[KeyPgType|Type]] | [[KeyPgClass|Class]] | [[KeyPgUnion|Union]] }
[[KeyPgFornext|For]] //iterator// [ As //typename// ] = //start_value// To //end_value// [ [[KeyPgFornext|Step]] //step_value// ]
[[KeyPgFornext|Next]]
name of the ##[[KeyPgType|Type]]##, ##[[KeyPgClass|Class]]##, or ##[[KeyPgUnion|Union]]##
##[[KeyPgOpFor|Operator For]]##, ##**Operator Next**## and ##[[KeyPgOpStep|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 ##[[KeyPgFornext|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 ##[[KeyPgOpFor|Operator For]]##, and immediately after any calls to its ##[[KeyPgOpStep|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 ##[[KeyPgFornext|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 ##[[KeyPgFornext|For...Next]]## statement. If a step value is given, the second version is used and is passed the step value.
See the [[KeyPgOpStep|Operator Step]] examples.
- Only available in the //[[CompilerOptlang|-lang fb]]// dialect.
- ##[[KeyPgOpFor|Operator For]]##
- ##[[KeyPgOpStep|Operator Step]]##
- ##[[KeyPgFornext|For...Next]]##
{ [[KeyPgType|Type]] | [[KeyPgClass|Class]] | [[KeyPgUnion|Union]] } //typename//
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **Next** ( [ [[KeyPgByref|byref]] | [[KeyPgByval|byval]] ] //cond// [[KeyPgAs|as]] //typename// ) [[KeyPgAs|as]] [[KeyPgInteger|Integer]]
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **Next** ( [ [[KeyPgByref|byref]] | [[KeyPgByval|byval]] ] //cond// [[KeyPgAs|as]] //typename//, [ [[KeyPgByref|byref]] | [[KeyPgByval|byval]] ] //stp// [[KeyPgAs|as]] //typename// ) [[KeyPgAs|as]] [[KeyPgInteger|Integer]]
End { [[KeyPgType|Type]] | [[KeyPgClass|Class]] | [[KeyPgUnion|Union]] }
[[KeyPgFornext|For]] //iterator// [ As //typename// ] = //start_value// To //end_value// [ [[KeyPgFornext|Step]] //step_value// ]
[[KeyPgFornext|Next]]
name of the ##[[KeyPgType|Type]]##, ##[[KeyPgClass|Class]]##, or ##[[KeyPgUnion|Union]]##
##[[KeyPgOpFor|Operator For]]##, ##**Operator Next**## and ##[[KeyPgOpStep|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 ##[[KeyPgFornext|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 ##[[KeyPgOpFor|Operator For]]##, and immediately after any calls to its ##[[KeyPgOpStep|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 ##[[KeyPgFornext|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 ##[[KeyPgFornext|For...Next]]## statement. If a step value is given, the second version is used and is passed the step value.
See the [[KeyPgOpStep|Operator Step]] examples.
- Only available in the //[[CompilerOptlang|-lang fb]]// dialect.
- ##[[KeyPgOpFor|Operator For]]##
- ##[[KeyPgOpStep|Operator Step]]##
- ##[[KeyPgFornext|For...Next]]##
Deletions:
{ [[KeyPgType Type]] | [[KeyPgClass Class]] | [[KeyPgUnion Union]] } //typename//
[[KeyPgDeclare declare]] [[KeyPgOperator operator]] **Next** ( [ [[KeyPgByref byref]] | [[KeyPgByval byval]] ] //cond// [[KeyPgAs as]] //typename// ) [[KeyPgAs as]] [[KeyPgInteger Integer]]
[[KeyPgDeclare declare]] [[KeyPgOperator operator]] **Next** ( [ [[KeyPgByref byref]] | [[KeyPgByval byval]] ] //cond// [[KeyPgAs as]] //typename//, [ [[KeyPgByref byref]] | [[KeyPgByval byval]] ] //stp// [[KeyPgAs as]] //typename// ) [[KeyPgAs as]] [[KeyPgInteger Integer]]
End { [[KeyPgType Type]] | [[KeyPgClass Class]] | [[KeyPgUnion Union]] }
[[KeyPgFornext For]] //iterator// [ As //typename// ] = //start_value// To //end_value// [ [[KeyPgFornext Step]] //step_value// ]
[[KeyPgFornext Next]]
name of the ##[[KeyPgType Type]]##, ##[[KeyPgClass Class]]##, or ##[[KeyPgUnion Union]]##
##[[KeyPgOpFor Operator For]]##, ##**Operator Next**## and ##[[KeyPgOpStep 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 ##[[KeyPgFornext 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 ##[[KeyPgOpFor Operator For]]##, and immediately after any calls to its ##[[KeyPgOpStep 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 ##[[KeyPgFornext 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 ##[[KeyPgFornext For...Next]]## statement. If a step value is given, the second version is used and is passed the step value.
See the [[KeyPgOpStep Operator Step]] examples.
- Only available in the //[[CompilerOptlang -lang fb]]// dialect.
- ##[[KeyPgOpFor Operator For]]##
- ##[[KeyPgOpStep Operator Step]]##
- ##[[KeyPgFornext For...Next]]##
Additions:
See the [[KeyPgOpStep Operator Step]] examples.
Deletions:
'' 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
%%