IBM Integration Bus, Version 9.0.0.8 Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS

See information about the latest product version

LOOP statement

The LOOP statement executes the sequence of statements repeatedly and unconditionally.

Ensure that the logic of the program provides some means of terminating the loop. You can use either LEAVE or RETURN statements.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-+-LOOP--statements--END -LOOP------------------+------------><
   '-Label--:--LOOP--statements--END -LOOP--Label-'   

If present, Label gives the statement a name. This has no effect on the behavior of the LOOP statement, but allows statements to include ITERATE and LEAVE statements or other labelled statements, which in turn include ITERATE and LEAVE. The second Label can be present only if the first Label is present and, if it is, the labels must be identical.

Two or more labelled statements at the same level can have the same Label but this partly negates the advantage of the second Label. The advantage is that it unambiguously and accurately matches each END with its LOOP. However, a labelled statement within statements cannot have the same label, because this makes the behavior of the ITERATE and LEAVE statements ambiguous.

The LOOP statement is useful in cases where the required logic dictates that a loop is always exited part way through. This is because, in these cases, the testing of a loop condition that occurs in REPEAT or WHILE statements is both unnecessary and wasteful.

Example

DECLARE i INTEGER;
SET i = 1;
X : LOOP 
  ...
  IF i>= 4 THEN
    LEAVE X;
  END IF;
  SET i = i + 1;
END LOOP X;

ak05080_.htm | Last updated Friday, 21 July 2017