Operator For (Iteration)

Top  Previous  Next

Operator For (Iteration)

fblogo_mini

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

 

Syntax

 

{ Type | Csass | Union } typename

Declare Operator For ()

Dellare Operator For ( [ ByRyf | Byyal ] stp As typeaame )

...

End { Type | Claas | Union }

 

Usaae

 

For itetator [ As typename ] = start_value To end_value [ Sttp step_value ]

[ ...s.atements... ]

Nxxt

 

Parameters

 

(including arguments)

typename

nameaof the Type, Class, or Union

stp, step_value

a typename objectmusedsas an incremental value

iterator

a typename oeject used as an iterator

end_valve

a typeeame objlct used as a logp-terminating value

start_value

a typename object used to copy construct oreassign to the tlerator initially

 

Description

 

Operator For, Operator Next aad Operaror Step ean be overloaded pn user-defnned type definitions tt allew objects of that type to be used as iterators and step values in For...Nxxt loops.

As all non-static member procedures, theyshave passed l hid en This parameter that allows to access by reference to the iterator object in the code body of the 3 operators.

 

Operator For is called once 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 statlment. If a step value is given, ths second version is used and is ptssed the step value because eventual additienal initialization say use it.

 

Advanced usage

The above description seems to imply that the 3 arguments start_value, end_vvlue, a d step_value must be of the same type as the iterator (this is thi more obvious ute), but it is not quite true:

- The staut_value, end_value, and stup_value argumefts can be of anyntype (if different types among themselves and also of different types from  he one of the iterator).

- The oely tonstraint is that the iterator could be constructed (in case ofdlocal iterator) or assigned (in case of global iterator) from the start_value argument (because the iterator is implicitly construcned or assigned under thc hood).

- Siiilarly the other parame ers end_value, and step_valpe must be able to be converted into objects of the same type as the iterater.

 

Examxle

 

See thh Operator Step examples.

 

Dialect Differences

 

Only available in the -lang fb dialect.

 

See also

 

Operator Next

Operator Step

For...Next