LOOP

#### Search Results

Search

# LOOP

[`CLOSE`] `LOOP` [(r)]

This document covers the following topics:

- LOOP Usage

- LOOP Restriction

- LOOP Syntax Description

- LOOP Examples

For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.

Belongs to Function Group: Reporting Mode Statements

## LOOP Usage

The `LOOP` statement is used to close a processing loop. It causes processing of the current pass through the loop to be terminated and control to be returned to the beginning of the processing loop.

When the processing loop for which the `LOOP` statement is issued is terminated (that is, when all records have been processed or iterations have been performed), execution continues with the statement after the `LOOP` statement.

The `LOOP` statement is used with the following statements: `CALL FILE`, `CALL LOOP`, `FIND`, `FOR`, `HISTOGRAM`, `PARSE JSON`, `PARSE XML`, `READ`, `READLOB`, `READ RESULT SET` (SQL), `READ WORK FILE`, `REPEAT`, `SELECT` (SQL), `SORT`, `UPLOAD PC FILE`.

### Database Variable References

A `LOOP` statement, in addition to closing a processing loop, will eliminate all field references to `FIND`, `FIND FIRST`, `FIND UNIQUE`, `READ` and `GET` statements contained within the loop.

A field within a view may be referenced outside the processing loop by using the view name as a qualifier.

## LOOP Restriction

- This statement is for reporting mode only.

- A `LOOP` statement may not be specified based on a conditional statement such as `IF` or `AT BREAK`.

## LOOP Syntax Description

Syntax Element | Description
--- | ---
`LOOP (r)` | Statement Reference Notation: The `LOOP` statement may be specified with a statement label or reference number (notation `(r)`), in which case all inner loops up to and including the loop initiated by the statement referenced will be closed. If no statement reference is specified, the innermost active processing loop will be closed.

Notes:

1. In reporting mode, any processing loop which is currently active, that is, which has not explicitly been closed with a `LOOP` statement, will be closed automatically by an `END` statement.
2. You can omit the `LOOP` statement. But with respect to good coding practice, you are not recommended to do so.

## LOOP Examples

#### Example 1

    FIND ...
      READ ...
        READ ...
    LOOP (0010)    /* closes all loops

#### Example 2

    FIND ...
      READ ...
        READ ...
        LOOP       /* closes loop initiated on line 0030
      LOOP         /* closes loop initiated on line 0020
    LOOP           /* closes loop initiated on line 0010

### On this page

- LOOP Usage
- LOOP Restriction
- LOOP Syntax Description
- LOOP Examples