Previous Topic: DO Control StatementNext Topic: Example


Syntax

DO	field = expression-1 TO expression-2 BY expression-3
	FOREVER UNTIL(condition) WHILE(condition)

where:

field

Specifies the name of the defined field (DEFINE control statement) that is to be set and incremented during the DO operation.

expression-1

Specifies an expression that defines the initial value for the DO operation.

expression-2

Specifies an expression that defines the final value or limit for the DO operation.

When the final value is exceeded, execution of the DO group is ended.

expression-3

Specifies an expression that defines the incrementing value for the DO operation.

If BY increment-expression is not specified, a value of +1 is used for an ascending range (expression-1 is less than or equal to expression-2), and a value of -1 is used for a descending range (expression-1 is greater than expression-2).

FOREVER

Specifies continual execution of the DO group.

The FOREVER keyword is mutually exclusive with the field = expression-1 TO expression-2 BY expression-3 specification.

UNTIL (condition)

Specifies that the execution of the DO group is to continue until the given condition is true.

WHILE (condition)

Specifies that the execution of the DO group is to continue while the specified condition is true.

All operands for the DO control statement are optional. If no operands are specified, or only field = expression-1 is specified, the DO group is executed one time only. The DO group continues to be executed until one of the following conditions is met:

The execution of the DO group can also be interrupted by a BREAK control statement, by a STOP control statement, or by an end-of-data condition retrieving database records or sort records.

DO control statements can be nested within IF control statements or other DO control statements to any level. Avoid an infinite loop when coding the UNTIL or WHILE conditions.

The DO control statement is convenient for printing multiple occurrences of address lines, special instruction lines, text specification entries, and history entries. The following example shows the printing of multiple occurrences of the text specification line, column, and text.