#LOOP / #BREAK

#LOOP

[ statements ]

#BREAK

[ statements ]

#END

statementsThe Template statements to execute each time.
#BREAKTerminates the loop.
#ENDThe #LOOP structure terminator.

The #LOOP structure iterates, executing the statements each time through the loop until a #BREAK statement executes. If there is no #BREAK then #LOOP iterates infinitely.

Example:

// This script creates a set attribute definition of the 1st 10
// natural numbers and defines an attribute named "Set10"

#DECLARE (SetString)
#DECLARE (Ndx)
#SET (SetString, '[');    //initialize SetString to [
#SET (Ndx, 1);            //initialize Ndx to 1
#LOOP
  #IF (%Ndx% > 9)  //if we've iterated 9 times
    #BREAK         // break out of the loop
  #ELSE            //otherwise
    #APPEND (SetString, %'Ndx'% + ',');
                   //append Ndx and comma to SetString
    #SET (Ndx, %Ndx% + 1)
                   //and increment the value of Ndx
  #END
#END
#APPEND (SetString, %'Ndx'% + ']'); //add 10th element and closing ]
EXPORT Set10 := %'SetString'%; //generate the ECL code
                               // This generates:
                               // EXPORT Set10 := [1,2,3,4,5,6,7,8,9,10];
OUTPUT(Set10); // [1,2,3,4,5,6,7,8,9,10]

See Also: #FOR, #DECLARE, #IF