In this topic, we described about the below sections -
The GO TO statement transfers control from one part of the procedure division to another. GO TO statement is a procedure division statement and should code in area-B.
If the GO TO statement is not the last statement in the sequence of imperative statements, the statements after GO TO are not executed. The types of GO TO statements are -
- More labels
Unconditional GO TO -
The unconditional GO TO statement transfers control to the first statement in the paragraph or section specified.
If the unconditional GO TO statement is not the last statement in a sequence of imperative statements, the statements following the GO TO are not executed.
Specifies a paragraph or a section in the same procedure division.
Conditional GO TO -
The conditional GO TO statement transfers control to the first statement in the paragraph or section specified depending on the value of the data item referenced by identifier-1.
Specifies a procedure or a section in the procedure division. The number of procedure-names must not exceed 255.
Specifies a numeric elementary data item that is an integer. identifier-1 cannot be a date field. If idetifier-1 value is 1, the control is transferred to the first statement in the procedure-name-1.If idetifier-1 value is 2, the control is transferred to the first statement in the procedure-name-2 and so forth.
If the value of identifier is anything other than a value within the range of 1 through n (where n is the number of procedure-names specified in GO TO statement), no control transfer occurs. Instead, control passes to the next statement in the normal sequence of execution.
Altered GO TO -
The altered GO TO statement transfers control to the first statement of the paragraph specified in the ALTER statement. Altered GO TO statement can’t specify in the following -
- A program or method that has the RECURSIVE attribute
- A program compiled with the THREAD compiler option
An ALTER statement referring paragraph that contains the altered GO TO statement should be executed before the GO TO statement is executed. Otherwise, the GO TO statement acts like a CONTINUE statement.
When an ALTER statement refers to a paragraph, the paragraph can consist only of the paragraph-name followed by an unconditional or altered GO TO statement.
MORE-LABELS GO TO -
The GO TO MORE-LABELS statement can specify a LABEL declarative.