[Next] [Up] [Previous]

The FOR Statement

Now, we examine control structures used for the repeated execution of a sequence of statements.

The FOR statement has the form

       FOR intvar=start,finish,increment;sequence

Recommended @-comments (if used):

       FOR intvar @FROM= start @TO, finish @BY, increment @DO; sequence

with @STEP, and @BY, equally recognized; &'FROM', &'TO', &'STEP' or &'BY', and &'DO' all also available.

If the sequence argument is omitted, the FOR statement only performs the action of setting the integer variable (intvar) to the value in the integer expression START, and it MUST be labelled with a statement number. This statement number may be used in GO_TO statements and so on (which is also true of a statement number used optionally in the other case).

The increment, used by the REPEAT statement, if omitted is considered to be 1.

If the sequence alternative is included, this statement performs the statements in sequence varying the value of intvar from start through all values less than or equal to finish that can be reached by adding increment, where increment is positive. For negative increment, the criterion is greater than or equal to finish.

In this form, this statement performs the actions in sequence zero times if finish cannot be reached from start by adding a quantity with the same sign as increment without overflow. A FOR-REPEAT loop, created with a FOR statement without the sequence argument, performs the actions within the loop at least one time even if its parameters are invalid.


[Next] [Up] [Previous]