1
An exit_statement is used to complete the execution of an enclosing loop_statement; the completion is conditional if the exit_statement includes a condition.
2
exit_statement::=
exit [loop_name] [when condition];
3
The loop_name, if any, in an exit_statement shall resolve to denote a loop_statement.
4
Each exit_statement (see 5.7) applies to a loop_statement (see 5.5); this is the loop_statement (see 5.5) being exited. An exit_statement (see 5.7) with a name is only allowed within the loop_statement (see 5.5) denoted by the name, and applies to that loop_statement (see 5.5). An exit_statement (see 5.7) without a name is only allowed within a loop_statement (see 5.5), and applies to the innermost enclosing one. An exit_statement (see 5.7) that applies to a given loop_statement (see 5.5) shall not appear within a body or accept_statement (see 9.5.2), if this construct is itself enclosed by the given loop_statement.
5
For the execution of an exit_statement, the condition, if present, is first evaluated. If the value of the condition is True, or if there is no condition, a transfer of control is done to complete the loop_statement (see 5.5). If the value of the condition is False, no transfer of control takes place.
NOTES
6
8 Several nested loops can be exited by an exit_statement that names the outer loop.
7
Examples of loops with exit statements:
8
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;
9
Main_Cycle: loop −− initial statements exit Main_Cycle when Found; −− final statements end loop Main_Cycle;