Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.

5.7. Exit Statements


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.

    exit_statement ::=
       exit [loop_name] [when condition]; 

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.

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.


    for N in 1 .. MAX_NUM_ITEMS loop
       exit when NEW_ITEM = TERMINAL_ITEM;
    end loop; 

          --  initial statements
          exit MAIN_CYCLE when FOUND;
          --  final statements
       end loop MAIN_CYCLE;


Several nested loops can be exited by an exit statement that names the outer loop.

References: accept statement, condition, evaluation, generic body, loop name, loop statement, package body, subprogram body, true boolean value.

Rationale references: 3.10 Short-Circuit Control Forms, 3.12 Loop Statements

Style Guide references: 5.1.3 Exit Statements, 5.6.4 Loops, 5.6.5 Exit Statements


[Ada Information Clearinghouse]

Address any questions or comments to