GOTO

The GOTO statement transfers program control to a point specified by a label.

Note: Using a GOTO to jump into the middle of a loop results in an error.

Note: You must be careful in programming with GOTO statements. It is easy to get into an infinite loop, especially if there is not an escape (or test) within the statements spanned by the GOTO.

Examples

In the following example, the statement at label JUMP1 is executed after the GOTO statement, skipping any intermediate statements:

GOTO, JUMP1
print, 'Skip this' ; This statement is skipped
print, 'Skip this' ; This statement is also skipped
JUMP1: print, 'Do this'

The label can also occur before the GOTO statement that refers to the label, but you must be careful to avoid an endless loop. GOTO statements are frequently the subjects of IF statements, as in the following statement:

if A ne G then GOTO, mistake

Syntax

GOTO, label

Version History

Original

Introduced

See Also

BEGIN...END, BREAK, CASE, CONTINUE, FOR, FOREACH, IF...THEN...ELSE, REPEAT...UNTIL, SWITCH, WHILE...DO

IDL Programming