for

The EGL keyword for begins a statement block that runs in a loop for as many times as a test evaluates to true. The test is conducted at the beginning of the loop and indicates whether the value of a counter is within a specified range. The keyword end marks the close of the for statement.


Syntax diagram for the for statement
counter
A numeric variable without decimal places. EGL statements in the for statement can change the value of counter.
from start
The initial value of counter. The initial value is 1 if you do not specify a clause that begins with from.
start can be any of these:
  • An integer literal
  • A numeric variable without decimal places
  • A numeric expression, which must resolve to an integer
to finish
If you do not specify decrement, finish is the upper limit of counter; and if the value of counter exceeds that limit, the test mentioned earlier resolves to false, the statement block is no longer executed, and the for statement ends.

If you specify decrement, finish is the lower limit of counter; and if the value of counter is below that limit, the test resolves to false, the statement block is no longer executed, and the for statement ends.

finish can be any of these:
  • An integer literal
  • A numeric variable without decimal places
  • A numeric expression, which must resolve to an integer

EGL statements in the for statement can change the value of finish.

by delta
If you do not specify decrement, delta is the value added to counter after the EGL statement block is executed and before the value of counter is tested.

If you specify decrement, delta is the value subtracted from counter after the EGL statement block is executed and before the value of counter is tested.

delta can be any of these:
  • An integer literal
  • A numeric variable without decimal places
  • A numeric expression, which must resolve to an integer

EGL statements in the for statement can change the value of delta.

statement
A statement in the EGL language

An example is as follows:

  sum = 0;

  // adds 10 values to sum
  for (i from 1 to 10 by 1)
    sum = inputArray[i] + sum;
  end

Related reference
EGL statements

Related tasks
Syntax diagram for EGL statements and commands

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.