FOR

Syntax

The FOR statement declares an INTEGER index variable that is local within the scope of the statement and, starting with a beginning value, is incremented or decremented to until the ending value is exceeded. The index variable may not be assigned a value within the body of the loop. The loop continues until after the ending value is reached or an EXIT or RETURN statement is executed within the loop.
FOR index-identifier IN [REVERSE] beginning-value .. ending-value
  LOOP statements 
END LOOP;

beginning-value := arithmetic-expression
	
ending-value := arithmetic-expression

statements :=
  statement; [statements]
Where,
index-identifier
Is a valid PL/MX identifier that specifies the name to associate with the index variable of the FOR statement. It can be referenced anywhere within the body of the FOR statement but cannot be referenced outside the FOR statement.
REVERSE
When included, means that the index-identifier is initialized to the ending-value and is decremented on each loop through the FOR statement until it is less than the beginning-value. If REVERSE is omitted, then the index-identifier is initialized to the beginning-value and is incremented on each loop until it is greater than the ending-value. The bound values are evaluated once, prior to the start of the loop, and remain constant thereafter.
statements

Is a series of PL/MX statements that are executed with each iteration of the loop.

Examples

A FOR statement that loops through the statements 10 times, incrementing the index-identifier from 1 through 10:

FOR loop_counter in 1..10 LOOP
		---- Perform some tasks…
END LOOP;

A FOR statement that loops through the statements n-2+1 times, decrementing the index-identifier from n through 2:

FOR inner_n IN REVERSE 2..n LOOP
  fact := fact * inner_n;
END LOOP;