[Home] [Prev] [Next] [Index]

5.9 Goto Statements

5.9 Goto Statements

1
A goto statement specifies an explicit transfer of control from this statement to a target statement named by a label.

2
goto_statement ::= goto label_name;

3
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.

4
The execution of a goto statement transfers control to the named target statement.

Note:

5
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.

6
Example:

<<COMPARE>>
      if A(I) < ELEMENT then
            if LEFT(I) /= 0 then
                  I := LEFT(I);
                  goto COMPARE;
            end if;
            -- some statements
      end if;

7
References:

*
accept statement 9.5

*
block statement 5.6

*
case statement 5.4

*
compound statement 5.1

*
exception handler 11.2

*
frame 11.2

*
generic body 12.1

*
if statement 5.3

*
label 5.1

*
package body 7.1

*
program unit 6

*
select statement 9.7

*
sequence of statements 5.1

*
statement 5.1

*
subprogram body 6.3

*
task body 9.1

*
transfer of control 5.1



[Home] [Prev] [Next] [Index]

documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights reserved.