Previous Topic Next topic Print topic


GOTO

Purpose

Transfers control to a labeled statement in the current procedure or in another active procedure.

Syntax

GOTOlabel-reference[OTHERWISE];

Alternate form: GO TO for GOTO

Abbreviation(s): OTHER for OTHERWISE.

Parameters

label-reference
Identifies a label value.

Description

The GOTO statement transfers control to a labeled statement in the current procedure or in another active procedure.

If the label value is a label variable or label-valued function, its value must designate a statement in the current procedure block or in a containing procedure block. The value must also designate a stack frame belonging to a Nock activation of that block.

If the statement to which control is transferred is not within the current block, the current block activation is ended, as are all previous block activations back to the block containing the statement. That block activation is made current, and control is transferred to the statement.

The OTHERWISE option can be used only with a subscripted GOTO statement. A subscripted GOTO statement is defined as a statement directing control to a label that is subscripted.

References to an invalid subscripted label in a GOTO statement are generally considered to be errors. For example, ALABEL ( 1 ) in the second example below, is an undefined member of the array, and ALABEL ( 3 ) is a member that is out of bounds of the array.

However, the OTHERWISE option can be used to cause control to pass to the statement that follows the GOTO statement if the element referred to is not a valid member of the array of label constants.

For a more complete discussion of label values, see the section Label Data in the chapter Data Types.

Example

GOTO L;
GOTO CASE(K); 
GO TO L;

The following example contains an array of subscripted label constants called ALABEL. The GOTO statement directs control to the statement that accompanies the subscripted label ALABEL (2) .

ALABEL(0): STATEMENT; 
ALABEL(2): STATEMENT;
   X = 2; GOTO ALABEL( X );

The following program sample presents the variable I used as a subscript in a GOTO statement that is subscripted on the third line. If the reference ALABEL ( I ) is not valid, the OTHERWISE option causes control to pass directly to the PUT LIST statement on the fourth line.

NEXT: GET LIST (I);
   GOTO ALABEL (I) OTHERWISE; 
   PUT LIST( "INVALID");
   GOTO NEXT;

ALABEL( 1 ):
   .
   .
   .
GOTO NEXT;

ALABEL( 2 ):
   .
   .
   .
GOTO NEXT;

Restrictions

None.

Previous Topic Next topic Print topic