FOREACH statement

The FOREACH statement offers a way to iterate arrays.

Syntax

          FOREACH (var1 AS var2 [KEY | INDEX var3] [SKIP NULLS]) DO
             <statements>

FOREACH loops over the array given by var1. On each loop, the value of the current element is assigned to var2. If the KEY (INDEX) var3 clause is specified, the current element's key will be assigned to the variable var3 on each loop.

Example

    MyVar = ibec_Array('Some text', 23, NULL, 56.32);
    foreach (MyVar as val key id) do
      if (val is not null) then
        ibec_ShowMessage('MyVar[' || id || '] value is: ' || val);

The code above is equal to following:

    MyVar = ibec_Array('Some text', 23, NULL, 56.32);
    for id = 0 to ibec_High(MyVar) do
    begin
      val = MyVar[id];
      if (val is not null) then
        ibec_ShowMessage('MyVar[' || id || '] value is: ' || val);
    end

This FOREACH statement with the SKIP NULLS option is equal to the following FOREACH statement without the SKIP NULLS option:

    FOREACH (var1 AS var2 [KEY | INDEX var3]) DO
    BEGIN
      IF (var2 IS NULL) THEN
        CONTINUE;
      <statements>     END

See also:
ibec_Array

back to top of page
<< FOR ... DO loops | IBEBlock | SELECT ... AS DATASET >>