Contents Index Previous Next
5.8 Goto Statements
1
[A goto_statement
specifies an explicit transfer of control from this statement
to a target statement with a given label.]
Syntax
2
goto_statement
::= goto label_name;
Name Resolution Rules
3
{target statement (of a goto_statement)}
The
label_name
shall resolve to denote a
label;
the
statement with that
label
is the
target statement.
Legality Rules
4
The innermost sequence_of_statements
that encloses the target statement shall also enclose the goto_statement.
Furthermore, if a goto_statement
is enclosed by an accept_statement
or a body, then the target statement shall not be outside this enclosing
construct.
4.a
Ramification: The goto_statement
can be a statement of an inner sequence_.
4.b
It follows from the second rule
that if the target statement is
enclosed by such a construct, then the goto_statement
cannot be outside.
Dynamic Semantics
5
{execution (goto_statement)
[partial]} The execution of a
goto_statement
transfers control to the target statement, completing the execution of
any
compound_statement that encloses
the
goto_statement but does not
enclose the target.
6
10 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 handled_sequence_of_statements
back to its sequence_of_statements.
Examples
7
Example of a
loop containing a goto statement:
8
<<Sort>>
for I in 1 .. N-1 loop
if A(I) > A(I+1) then
Exchange(A(I), A(I+1));
goto Sort;
end if;
end loop;
Contents Index Previous Next Legal