1. DO Statement

The DO statement defines conditions for repeated execution on a multiple statements groups. A DO statement must be used along with an END statement. Statements between a DO statement and an END statement are grouped as a do-group.

A DO statement can be one of the following types:

  • Type 1

  • Type 2

  • Type 3

  • Type 4

Type 1

Type 1 defines a do-group and executes statements within the do-group. Type 1 does not define conditions for repeated execution.

figure syntax do type1
DO Statement Type 1

Type 2 and Type 3

Type 2 and Type 3 define a do-group and executes statements within the do-group. They can define conditions for repeated execution.

Type 2:

figure syntax do type2
DO Statement Type 2

Type 3:

figure syntax do type3
DO Statement Type 3

specification:

image

Component Description

WHILE(expression)

Evaluates an expression and converts it to a BIT string before executing a do-group.

If any BIT in a string are 1, a do-group will be executed. If all BITs are 0 or a string is NULL, a do-group will not be executed.

If there are multiple specifications, the next specification will be executed.

UNTIL(expression)

Evaluates an expression and converts it to a BIT string after executing a do-group.

If all BITs in a string are 0 or the string is NULL, a do-group will be executed. If any BIT is 1, a do-group will not be executed.

If there are multiple specifications, the next specification will be executed.

reference

The value of expression1 will be used for initialization before executing a do-group.

If there are multiple specifications, each specification’s value of expression1 will be used for initialization.

expression1

Initial value of a reference.

If TO, BY, and REPEAT are omitted, the value of expression1 will always be used for initialization.

TO expression2

The end value of a reference. If a value of a reference is not in the range of values between expression1 and expression2, a corresponding do-group will be ended.

If TO expression2 is omitted, a do-group will be ended by the WHILE or UNTIL options.

BY expression

Increment to a reference. A reference is added by the value of an expression after executing a do-group.

If TO expression2 is specified and BY expression is omitted, BY 1 will be the default value.

UPTHRU expression

The end value of a reference. A reference is increased by 1 and saved after executing a do-group.

The TO option is compared before executing a do-group but the UPTHRU option is compared after executing a do-group. Therefore, the UPTHRU option allows a do-group to be executed at least once.

DOWNTHRU expression

The end value of a reference. A reference is subtracted by 1 and saved after executing a do-group.

The TO option is compared before executing a do-group but the DOWNTHRU option is compared after executing a do-group. Therefore, the DOWNTHRU option allows a do-group to be executed at least once.

REPEAT expression

The expression is evaluated, the result value is saved to a reference, and a do-group is executed.

A do-group execution is repeated until ended by the WHILE or UNTIL options.

Type 4

Type 4 defines a do-group and executes statements within the do-group repeatedly and infinitely.

figure syntax do type4
DO Statement Type 4
Component Description

FOREVER

Same as LOOP.

LOOP

Sets infinite repetition.

To end the repetition, use a GOTO or LEAVE statement or end the procedure or program.