You are here: Commands > Loop

Loop

Use the Loop command within a Group command to process a record more than once. Loops are frequently used when a record contains repeated information, sometimes called buckets or segments, that you want to process. Commands between Loop and End are executed repeatedly on the current record until the result of the test is false.

Loops can only be used within groups. Before you create a loop, you should be familiar with the concepts involved in creating groups. For more information, see Group.

For a more detailed description using the Loop command to process multiple record type files see Multiple-Record-Type Files.

Parameters

The Loop command has the following parameter: While. For a description, see Command Parameters.

Command Mode Syntax

Each Loop command must be closed with an End command. Within a Loop, you must specify While parameters to test for a condition. The commands between Loop and End are executed repeatedly for the current record as long as the While test specified is true. If the While test is initially false, the commands are not executed.

Note: To avoid creating an infinite loop, make sure that the test you specify eventually returns false. You can also use the Loop option of the Set command to prevent infinite looping. See Set Loop for details.

LOOP WHILE test¿

commands¿

...¿

END¿

Examples

The following Loop command totals 100 bucketed fields in a record, assuming each bucket is five bytes long:

GROUP¿

COUNT=0¿

TOTAL=0¿

LOOP WHILE COUNT<100¿

TOTAL=TOTAL+OFFSET(AMOUNT,COUNT*5)¿

COUNT=COUNT+1¿

END¿

END¿