WebSphere Message Brokers
File: ak05070_
Writer: Bill Oppenheimer

Reference topic

This build: July 31, 2007 21:31:32

LEAVE statement

The LEAVE statement stops the current iteration of the containing WHILE, REPEAT, LOOP, or BEGIN statement identified by Label.

The containing statement's evaluation of its loop condition (if any) is bypassed and looping stops.

Syntax

Examples

In the following example, the loop iterates four times:
DECLARE i INTEGER;
SET i = 1;
X : REPEAT 
  ...
  IF i>= 4 THEN
    LEAVE X;
  END IF;

  SET i = i + 1;
UNTIL
  FALSE
END REPEAT;
LEAVE statements do not have to be directly contained by their labelled statement, making LEAVE statements particularly powerful.
DECLARE i INTEGER;
SET i = 0;
X : REPEAT                   -- Outer loop
  ...
  DECLARE j INTEGER;
  SET j = 0;
  REPEAT                     -- Inner loop
    ...
    IF i>= 2 AND j = 1 THEN
      LEAVE X;               -- Outer loop left from within inner loop
    END IF;
    ...
    SET j = j + 1;
  UNTIL
    j>= 3
  END REPEAT;

  SET i = i + 1;
UNTIL
  i>= 3
END REPEAT X;
                             -- Execution resumes here after the leave
Related concepts
ESQL overview
Related tasks
Developing ESQL
Related reference
Syntax diagrams: available types
ESQL statements
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:31:32

ak05070_ This topic's URL is: