Please enable JavaScript to view this site.

ESL Documentation

Action Statement

Specify a set of action statements to be performed repeatedly.

for INTEGER_VAR_NAME = VALUE1 to VALUE2 [by VALUE3]

 loop [LOOP_NAME]

 [ACTION_STATEMENT] ...

 [ leave loop [LOOP_NAME] ]

 [ACTION_STATEMENT] ...

 end loop [LOOP_NAME]

INTEGER_VAR_NAME

A previously defined integer variable.

VALUEn

An integer value.

LOOP_NAME

The identifier for a loop.

ACTION_STATEMENT

An action statement.

leave loop LOOP_NAME

Upon execution, exit from the loop and continue execution at the statement following the end loop keywords. The leave loop action statement can be one of the action statements in a for loop statement. If you specify a leave loop statement, you must specify it within the definition of the loop itself. You cannot specify it in an action routine that is called from inside the loop.

LOOP_NAME can be the loop in which you specify the leave loop, or an outer loop. If you specify an outer loop, ESL leaves the specified outer loop and all inner loops. If you do not specify a name in the leave loop statement, ESL exits from the innermost loop that contains the leave loop statement, even if the innermost loop has a name.

Description

The for loop statement extends while loop support by allowing a specification of an initial value for the loop variable. It also allows automatic incrementing or decrementing of the loop variable, until the integer variable reaches a specified value.

When ESL encounters a for statement, it initializes INTEGER_VAR_NAME (IVN) to VALUE1. If IVN is less than VALUE2, the loop is executed. The next time through the loop, IVN is incremented by VALUE3. (If you do not provide VALUE3, then ESL uses a value of 1. Specify a negative value for VALUE3 to cause VALUE1 to go from a larger to a smaller value.) Then IVN is tested against VALUE2. The value of IVN when the loop is ended will be the first increment value that caused the loop to fail.

If VALUE3 is zero, the loop will not be executed. If the current value of IVN is less than VALUE2, and VALUE3 is negative, the loop is terminated. Similarly, if the current value of IVN is greater than VALUE2, and VALUE 3 is positive, the loop is terminated.

You can use a for loop statement within a response definition, an action routine definition, or an ESL subroutine. You can include it within a conditional action statement or within other loops, to any number of levels. You can specify blocks in loops, and vice versa. If you specify a block within a loop, execution of a leave loop statement causes all blocks contained in the loop to become inactive.

The identifier used to name the loop must be unique within the ESL program; there must be nothing else in the program with that name. If you specify a name in the for loop statement, you must include a name in the end loop statement that exactly matches the name specified in the for loop.

Example

 

integer A

 

for A = 1 to 5 loop # Uses default increment of 1

 send A "\n" to errorlog

end loop

 

# The loop can also go down, in which case VALUE3 should

# be negative.

 

integer A

 

for A = 5 to 1 by -2 loop

 send A "\n" to errorlog

end loop

See Also

while loop Action Statement