Friday, September 4, 2009


The GO Statement
Syntax
Format 1
GO TO procedure-name-1
Format 2
GO TO {procedure-name-1}... DEPENDING ON identifier-1
Format 3
GO TO.
Description
The GO statement is used to transfer control to another part of the program. Each of the three formats works slightly differently and is described in the correspondingly numbered area.
1. The first format unconditionally transfers control to the referenced procedure. There is no way to determine from where the control was transferred and there is no way to return to the transferring location.
2. The second format unconditionally transfers control to one of the referenced procedures. The exact procedure control is transferred to depends on the value of the identifier. If the identifier has a value of one, control will be transferred to the first procedure listed; if the value is two, control will be transferred to the second procedure, and so on. If there is not a procedure name listed to correspond with the value of the identifier at run time, the GO TO statement will have no effect and control will pass to the next consecutive statement. There is no way to determine from where the control was transferred and there is no way to return to the transferring location.
3. The third format is used in conjunction with the ALTER statement. The actual location for the control transfer is determined at run time using the ALTER statement. It must be the only statement in its respective paragraph. If no ALTER statement affecting the GO TO has been executed prior to executing a format 3 GO TO, the statement will have no effect. There is no way to determine from where the control was transferred and there is no way to return to the transferring location.

Tips
1. Do not use the GO statement. A well-structured, easy to follow program is accomplished via the PERFORM statement.
2. The functionality once realized via the GO TO statement with the DEPENDING ON phrase is better implemented with an EVALUATE statement.
3. The third format of the GO statement should never be used as it is marked for deletion from the next release of the COBOL standard. It is also responsible for creating programs that are almost impossible to debug.