The for Statement

The for statement lets you repeat a statement or compound statement until a particular condition is satisfied. It can also execute a loop until an expression evaluates to false. In this case, the execution terminates.

This page discusses:

See Also
Variables

Syntax

The general form of the syntax can be expressed as follows:

  • For <variable name> inside <list variable name>
    {
    
    }
    
  • For <variable name> while <condition>
                    <instruction>
    

Use

You can use the for statement to execute a loop based on the element of a list. The form of the syntax can be expressed as follows:
let List1(List) 
       let x(Point) 
       For x inside List1
       {
               ... Body ... 
               if (x <> NULL)
                    ...
       }

Where:

  • x is a variable name (of a given type). It can represent an object or a value.
  • x can be used in the body (like any other variable of the language). It contains the element of the list corresponding to the current iteration.
  • List1 is a variable name of type List or an expression returning a list.
Notes:
  • The body is executed Nth times where N is the number of elements of the list.
  • You can declare the variable at the beginning of the script. The variable of the loop must be an integer:
    let i(Integer)
    for i = 2 while i<50
    {
    //EKL Actions
    }
    
  • You can initialize the variable with an instruction that returns an Integer. The variable of the loop must be an integer:
    let i(Integer)
    for i = 2*2+1 while i<50
    {
    //EKL Actions
    }
    
You can use the for statement to execute a loop that stops only when an expression becomes false. The form of the syntax can be expressed as follows:
For x while predicate 
       { 
         ... Body ... 
       }

Where:

  • x is a variable name of integer type. It is incremented at the end of each execution of the body unless it has been explicitly changed in the body.
  • predicate is a Boolean expression. The body is executed if this expression is true. This expression is evaluated before the body.
Note: Using the for statement in such a configuration can lead to infinite loops.