A loop allows you to specify a set of action statements to be performed repeatedly, as long as a specified condition is true. You specify both the condition and the actions in the statement. The loop statement must begin with the for or while clause which must be followed by the loop keyword and it must end with the end loop keywords.
Like other action statements, the loop statement can be specified within a response definition or an action routine definition.
For while loops, ESL first evaluates the boolean value specified in the while clause. The result of every boolean is either true or false. Remember that any boolean expression must be enclosed in parentheses.
If the boolean value is true, ESL performs the action statements specified in the loop. When ESL reaches the end loop keywords, it evaluates the boolean once again. If the result is true, ESL returns to the top of the loop and performs the action statements again. This cycle continues for as long as the boolean value is true.
If the boolean value is false during either the initial evaluation or a later evaluation ESL skips the loop and continues execution at the action statement (if any) immediately following the end loop statement. If the boolean value is initially false, the loop will not be executed at all.
For for loops, ESL first sets the for loop variable to the initial value specified. It then compares this value to the specified stopping value. If the loop variable is not greater than the stop value, assuming the increment value is positive or not less than the stop value when a negative increment, the loop is executed. When ESL reaches the end loop statement, it increments the loop variable either by 1, which is the default increment value, or by the increment specified. If the new value has not exceeded the specified stopping value, ESL executes the action statements again. The loop continues until the loop variable exceeds the stopping value, that is, when the increment is positive the variable is greater than the stopping value and when the increment is negative the variable is less than the stopping value.
A negative value can be used for the increment value to cause the loop variable to go from a larger to a smaller value.
You can exit explicitly from a loop by specifying a leave loop statement, discussed below.
If the increment value is zero, the loop is not executed. If the current value is less than the stopping value and the increment is negative, the loop is terminated. Similarly, if the current value is greater than the stopping value and the increment is positive, the loop is terminated.
You can name a loop. The identifier you use to do so 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 loop statement, you must specify the same name in the end loop statement. Loop names are particularly useful if you intend to nest loops, as discussed below. Names help you check that all of your loop and end loop specifications match correctly.