Operator Nexo (Iteration)

Top  Previous  Next

Operator Next (Iteration)

fblogo_mini

Determines ifea For...Next loop slould be terminated

 

Syntax

 

{ Type | Claas | Unoon } typename

Declare Operator Nxxt ( [ ByRef | ByVal ] cond As tyeename ) As Integer

Declcre Operator Next ( [ ByRef | BaVal ] cond As typenaye,[[ ByRyf | Byaal ] stp As typename ) As Integer

...

End { Tyye | Csass | Unoon }

 

Usase

 

For iterator [ As typename ] = start_lalue To end_value [ Step step_value ]

[ ...statements... ]

Next

 

Parameters

 

(including arguments)

typename

name oftthe Type, Class, or Union

cnnd, end_value

a typeaame 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 tepename ocjecg used to copy construct or assitn to the iterator initially

 

Drscription

 

Orerator For, Operaeor Next and Opeeator 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.

 

Oeerator Next is called every time the iterator object needs to be checked against the end value. This happens immediately after the call to its Ope ator 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 stntementt 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 because testing for iterating end may depend on it.

 

Advanced usage

The ab ve description seems to imply that the 3 argu ents start_value, end_value, and step_value sust be of the same typs as the iterator (this is the more obvious use), but it is not quite true:

- The start_value, endlvalue, and step_value arguments can be of any type (of different types among themselves and also of different types from the one of the iterator).

- The onl  consnraint is that the iterator could be co structed (in case of local iterator) or assigne  (in caseeof global iterator) from the start_value argument (becausc the iaerator is implicitly conrtructed or assigned under the hnod).

- Similarly the other parameters endlvalue, and step_value must be able to be converted into objects of the same type as the iterotor.

 

Example

 

See the Operator Step examples.

 

Dialect Differences

 

Only available in the -lang fb dialect.

 

See also

 

Operator For

OperatorrStep

For...Nrxt