Caché MultiValue Basic Reference
GOTO
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

Transfers program execution to a label.
Synopsis
GOTO label
G label
Arguments
label Any valid label. The label name can be optionally followed by a colon (:)
Description
The GOTO statement is used to transfer execution to the line of code identified by label. The label argument value corresponds to line of code identified by a label identifier. Numeric labels do not use a colon suffix. Non-numeric labels end with a colon character; this colon is option when specifying the label argument.
G is an abbreviation for the GOTO statement. The GOSUB statement is similar to GOTO, except that it permits a RETURN. The ON statement provides a way to select one of several GOTO labels, based on an integer value.
Commonly, GOTO is used within a code block of an IF...THEN statement.
GOTO can be used to exit from a FOR...NEXT or LOOP...REPEAT loop. You can also use the EXIT statement to cause execution to jump out of a FOR...NEXT or LOOP...REPEAT loop. You can use the CONTINUE statement to cause execution to jump back to the FOR or LOOP statement to perform the next loop iteration.
GOTO can be used to enter the middle of a FOR...NEXT or LOOP...REPEAT loop. This use of GOTO is generally not recommended, and is not supported in other Caché languages, such as ObjectScript.
Emulation
jBASE emulation uses the ONGO.RANGE option setting for handling out-of-range label values.
Examples
The following examples illustrate the use of the GOTO statement with numeric and non-numeric labels:
Numeric label:
  IF TIME()=0 THEN
    GOTO 20
  ELSE
    PRINT Time()
  END IF
  END
20
  PRINT "It's midnight, time is reset to 0"
  END
Non-numeric label:
  IF TIME()=0 THEN
    GOTO Midnight
  ELSE
    PRINT Time()
  END IF
  END
Midnight:
  PRINT "It's midnight, time is reset to 0"
  END
See Also