LOOP command

Used inside the GROUP command to process one or more commands repeatedly while a test condition is true.

Syntax

LOOP WHILE test
  command
  <...n>
END

Parameters

WHILE test

Specifies the test that must evaluate to true for the commands inside the LOOP command to be executed. If the test evaluates to true the commands are executed repeatedly until the test evaluates to false.

command

Specifies the command to execute. You can enter multiple commands inside the LOOP command. Each command must start on a new line.

END

Specifies the end of the LOOP command.

Remarks

Loops are frequently used when a record contains repeated segments of data that you want to process.

Each LOOP command must specify a WHILE condition to test for a condition, and be closed with an END statement. The commands between LOOP and END are executed repeatedly for the current record as long as the test specified is true. If the test is initially false, the commands are not executed.

To avoid creating an infinite loop, make sure that the test you specify eventually returns false. You can also use the SET LOOP command to prevent infinite looping.

Example

The following LOOP command totals 100 segments in a record, assuming each segment is five bytes long:

GROUP
  v_counter = 0
  v_total = 0
  LOOP WHILE v_counter < 100
    v_total = v_total + OFFSET(Amount, v_counter * 5)
    v_counter = v_counter + 1
  END
END
Related reference
GROUP command


(C) 2013 ACL Services Ltd. All Rights Reserved. | Send feedback