A goto statement specifies an explicit transfer of control from this statement to a target statement named by a label.
goto_statement ::= goto label_name;
The innermost sequence of statements that encloses the target statement must also enclose the goto statement (note that the goto statement can be a statement of an inner sequence). Furthermore, if a goto statement is enclosed by an accept statement or the body of a program unit, then the target statement must not be outside this enclosing construct; conversely, it follows from the previous rule that if the target statement is enclosed by such a construct, then the goto statement cannot be outside.
The execution of a goto statement transfers control to the named target statement.
The above rules allow transfer of control to a statement of an enclosing sequence of statements but not the reverse. Similarly, they prohibit transfers of control such as between alternatives of a case statement, if statement, or select statement; between exception handlers; or from an exception handler of a frame back to the sequence of statements of this frame.
<<COMPARE>> if A(I) < ELEMENT then if LEFT(I) /= 0 then I := LEFT(I); goto COMPARE; end if; -- some statements end if;
References: accept statement, block statement, case statement, compound statement, exception handler, frame, generic body, if statement, label, package body, program unit, select statement, sequence of statements, statement, subprogram body, task body, transfer of control.
Style Guide references: 5.6.7 Goto Statements, 5.8.1 Handling Versus Avoiding Exceptions
Address any questions or comments to firstname.lastname@example.org.