DGL Statement Reference : FOR/LOOP

FOR/LOOP

Description
Provides iterative execution of template statements.
The FOR/LOOP construct is used to execute iterative DGL statements. This statement executes the statements between LOOP and END LOOP for each item in the specified list. The identifier is a variable whose value is set sequentially to the items in the list. This variable can be used within the body of the loop, but its value cannot be reassigned.
Alternatively, a range of integers can be specified in place of the list, as in the following example:

FOR i IN {1..100} LOOP
statement;
.
.
.
END LOOP;

Syntax
FOR identifier IN list
LOOP [statement;]
.
.
.
END LOOP;
Parameters
 
A variable whose value is set sequentially to the items in the list. The type of the identifier must match the type of the list. This variable can be used within the body of the loop.

 

Notes
The type of the variable identifier must match the type of the list. The list can be a range of integers written as follows, where x is an integer variable:

FOR x IN {1..100} LOOP ...

Example
This example writes to the output file the names of all the states in the list statelist:

FOR id IN statelist LOOP
WRITE (’\n’, stm_r_st_name (id, status));
END LOOP;

See Also