Go To (GOTO)

Where allowed to run:
  • Batch program (*BPGM)
  • Interactive program (*IPGM)
Threadsafe: Yes
Parameters
Examples
Error messages

The Go To (GOTO) command is used in CL procedures for branching from one part of the program to another. The branching is to the label on another command that is specified on the Go To (GOTO) command. Branching can be either forward or backward, but the specified label must be inside the program. For a GOTO command in a subroutine, the branch target must be associated with the same subroutine.

Restrictions:

Top

Parameters

Keyword Description Choices Notes
CMDLBL Command label Simple name Required, Positional 1
Top

Command label (CMDLBL)

Specifies the label name of the command to which control is transferred; when the Go To (GOTO) command is processed. The command with the label is then processed. If the specified command cannot be run (for example, if it is a DCL command), control is transferred to the next command following the command with the specified label. The label must be within the same program as the GOTO command. A CL variable name cannot be used to specify the label name.

This is a required parameter.

Top

Examples

LOOP:  CHGVAR &A (&A + 1)
IF  (&A *LT 30)  THEN(GOTO  LOOP)

The Change Variable (CHGVAR) command increases the value of &A by 1 until &A is equal to or greater than 30. The GOTO command is processed each time that the IF command tests the expression and the result is true; the GOTO command following the THEN parameter causes the procedure to branch back to the label LOOP on the CHGVAR command. Refer to the descriptions of the CHGVAR command and the IF command for additional explanations of their functions.

Top

Error messages

None

Top