[Home] [Prev] [Next] [Index]
5.7 Exit Statements
5.7 Exit Statements
- 1
- An exit statement is used to complete the execution of an enclosing loop statement (called the loop in what follows); the completion is conditional if the exit statement includes a condition.
- 2
- exit_statement ::=
exit
[loop_name] [when
condition];
- 3
- An exit statement with a loop name is only allowed within the named loop, and applies to that loop; an exit statement without a loop name is only allowed within a loop, and applies to the innermost enclosing loop (whether named or not). Furthermore, an exit statement that applies to a given loop must not appear within a subprogram body, package body, task body, generic body, or accept statement, if this construct is itself enclosed by the given loop.
- 4
- For the execution of an exit statement, the condition, if present, is first evaluated. Exit from the loop then takes place if the value is TRUE or if there is no condition.
- 5
- Examples:
for
N in
1 .. MAX_NUM_ITEMS loop
GET_NEW_ITEM(NEW_ITEM);
MERGE_ITEM(NEW_ITEM, STORAGE_FILE);
exit when
NEW_ITEM = TERMINAL_ITEM;
end loop
;
MAIN_CYCLE:
loop
-- initial statements
exit
MAIN_CYCLE when
FOUND;
-- final statements
end loop
MAIN_CYCLE;
- Note:
- 6
- Several nested loops can be exited by an exit statement that names the outer loop.
- 7
- References:

- accept statement 9.5

- condition 5.3

- evaluation 4.5

- generic body 12.1

- loop name 5.5

- loop statement 5.5

- package body 7.1

- subprogram body 6.3

- true boolean value 3.5.3
[Home] [Prev] [Next] [Index]
documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights
reserved.