Document Templates : DGL Statements : Control Flow Statements : FOR/LOOP Statement

FOR/LOOP Statement

Statement Syntax:

FOR identifier IN list LOOP
statements
END LOOP ;

The FOR/LOOP construct is used for iterative execution of DGL statements. The statements after the keyword LOOP are executed for each element in the specified list.

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 ;

The identifier is 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 may be used within the body of the loop.

The following example writes the name and synonym for each state found in the list defined by the variable sub_states:

VARIABLE
STATE st_id ;
LIST OF STATE sub_states;
.
.
.
FOR st_id IN sub_states LOOP
WRITE(stm_r_st_name(st_id,status), ’ ’,
stm_r_st_synonym(st_id,status), ’\n’) ;
END LOOP ;