HP 3000 Manuals

GO TO Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

GO TO Statement 

The GO TO statement transfers control from one part of the PROCEDURE
DIVISION to another.
[REV BEG]

The optionality of procedure-name-1 of the GO TO statement is an obsolete
feature of the 1985 ANSI COBOL standard.  See the description below for
more information.[REV END]

Syntax 

The GO TO statement has two formats:

     GO TO [procedure-name-1]

     GO TO {procedure-name-1}...DEPENDING ON identifier-1 

Parameters 

procedure-name-1  and its subsequent occurrences are names of procedures
                  within the PROCEDURE DIVISION of your program.

identifier-1      the name of a numeric elementary data item that has no
                  positions to the right of the decimal point.

Description 

The first format of the GO TO statement transfers control to the
procedure named by procedure-name-1 or, if no procedure is named, to the
procedure specified in a previously executed ALTER statement.  An ALTER
statement must be issued for this type of GO TO statement before it is
executed if no procedure is named in it.  This also implies that a GO TO
statement without a procedure name specification must make up the only
sentence in a paragraph.  Refer to the ALTER statement description in
this chapter for other restrictions.
[REV BEG]

Both the ALTER statement and the optionality of procedure-name-1 in the
GO TO statement are obsolete features of the 1985 ANSI COBOL
standard.[REV END] 

If the first format of the GO TO statement does specify a procedure name
and if it appears in a sequence of imperative statements within a
sentence, it must be the last statement in that sentence.

In the second format of the GO TO statement, identifier must be the name
of a numeric elementary item described with no positions to the right of
the decimal point.  It is used to determine which procedure is to be
executed.  If the contents of identifier is an integer in the range one
to n, where n is the number of procedure names appearing in the GO TO
statement, then control passes to the procedure in the position
corresponding to the value of identifier.  Otherwise, no transfer occurs
and control passes to the next statement following the GO TO statement.

Examples 

In the program below, the GO TO statement in the GO-PARA paragraph is
equivalent to GO TO WHICH because of the ALTER statement preceding
it.[REV BEG] This form of the GO TO statement is an obsolete feature of
the 1985 ANSI COBOL standard.[REV END]

The second GO TO statement branches to UNDER, OVER, or EXACT, depending
upon whether SELECTOR has a value of 1, 2, or 3 respectively.  If
SELECTOR has any other value, the DISPLAY statement is executed.

     WORKING-STORAGE SECTION.
     01 SELECTOR            PIC 9(3).
           :
     PROCEDURE DIVISION.
              :
          ALTER GO-PARA TO PROCEED TO WHICH.
              :
     GO-PARA.  GO TO.
     AFTER-GO-PARA.
              :
          GO TO UNDER, OVER, EXACT DEPENDING ON SELECTOR.
          DISPLAY "SELECTOR OUT OF RANGE - VALUE IS ", SELECTOR.
              :
     UNDER.
       :
     OVER.
       :
     EXACT.
       :
     WHICH.
       :



MPE/iX 5.0 Documentation