Updated on 2023-10-31 GMT+08:00

Loop Statements

Simple LOOP Statements

The syntax diagram is as follows.

Figure 1 loop::=

Example:

The loop must be exploited together with EXIT; otherwise, a dead loop occurs.

WHILE-LOOP Statements

The syntax diagram is as follows.

Figure 2 while_loop::=

If the conditional expression is true, a series of statements in the WHILE statement are repeatedly executed and the condition is decided each time the loop body is executed.

Examples

FOR_LOOP (Integer variable) Statement

The syntax diagram is as follows.

Figure 3 for_loop::=
  • The variable name is automatically defined as the integer type and exists only in this loop. The variable name falls between lower_bound and upper_bound.
  • When the keyword REVERSE is used, the lower bound must be greater than or equal to the upper bound; otherwise, the loop body is not executed.

Example:

FOR_LOOP Query Statements

The syntax diagram is as follows.

Figure 4 for_loop_query::=

The variable target is automatically defined, its type is the same as that in the query result, and it is valid only in this loop. The target value is the query result.

Example:

FORALL Batch Query Statements

The syntax diagram is as follows.

Figure 5 forall::=

The variable index is automatically defined as the integer type and exists only in this loop. The index value falls between low_bound and upper_bound.

Example: