for

The EGL for statement governs a loop that runs until a counter reaches a specified value. You provide an initial value for the counter, a limit for the counter, and an optional amount that EGL uses to automatically increase or reduce the value of the counter after completing each loop. The keyword end marks the close of the forstatement.

Syntax

Syntax diagram for the for statement
label
A label, followed by a colon, which a continue or exit statement can reference. For more information, see Conditional and loop statements.
counter
A numeric variable without decimal places. EGL statements within the for statement can change the value of counter. You can declare the counter variable within the for statement.
start
The initial value of counter. The default value is 1.
start can be any of the following values:
  • An integer literal
  • A numeric variable without decimal places
  • A numeric expression, which must resolve to an integer
finish
The upper limit of counter (or the lower limit if you use the decrement option); if the value of counter exceeds that limit, the for statement ends.
finish can be any of the following values:
  • An integer literal
  • A numeric variable without decimal places
  • A numeric expression, which must resolve to an integer

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

decrement
By default, EGL increases the value of counter by the value of delta after each trip through the loop. This optional keyword tells EGL to reduce the value of counter by that amount instead.
delta
The value EGL uses to change counter at the end of each cycle and before testing counter.
delta can be any of the following values:
  • 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.

If you do not specify a delta value, EGL assumes a value a 1.

statement
A statement in the EGL language.

Example

In the following example, the counter i is declared within the for statement:

  sum = 0;

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

Feedback