This function allows you to organize the iteration by all elements contained in the specified array, vector, or enumeration so as to execute a certain operation for each iterated element.

The function iterates by all elements (starting from the first one) and on each step assigns the current element to a special external variable, whose reference is passed in the stepVar parameter (using special '@' operator). That variable is also accessible within the subquery specified in stepQuery parameter. The function executes that subquery for each element, so the specified operation is processed for that element.

Basically, the function works as the following loop (in the case of array; for a vector or enumeration that loop is similar):


index = 0;
while (index < a.length())
{
  step_var = a[index];

  // step subquery operators
  // ...

  index = index + 1;
}
(However, at the moment, the while operator is not supported in FlexQuery expressions, hence the need of this function.)

Parameters:

a / v / e

Specifies the array, vector, or enumeration containing the elements to be iterated.

Note: If this parameter is null, the function does nothing and returns 0.

stepVar
The reference to the variable to which the current iterated element is assigned to pass it to the subquery on each iteration step.

The variable reference must be produced using '@' operator (see example below).

stepQuery
Specifies the subquery to be executed for each element.

The subquery should be prepared using FlexQuery() function (see example below).

Returns:

The number of iterations that has been made.

See Also:

FlexQuery()

Example:

The following expression creates a vector containing non-null elements provided by the enumeration passed in 'enum' variable and returns that vector as the expression result:


v = Vector();  // create an empty vector

// iterate by enumeration elements 
// and fill the vector

iterate (
  enum, 
  @el,
  FlexQuery ({
    (el != null) ? { v.addElement(el) }
  })
);

v  // return the vector