Previous IDL Reference Guide: Procedures and Functions Next

GOTO

Syntax | Examples | Version History

The GOTO statement transfers program control to point specified by a label. The GOTO statement is generally considered to be a poor programming practice that leads to unwieldy programs. Its use should be avoided. However, for those cases in which the use of a GOTO is appropriate, IDL does provide the GOTO statement.

Note that using a GOTO to jump into the middle of a loop results in an error.


Warning
You must be careful in programming with GOTO statements. It is not difficult to get into a loop that will never terminate, especially if there is not an escape (or test) within the statements spanned by the GOTO.

For information on using GOTO and other IDL program control statements, see Program Control.

Syntax

GOTO, label

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  

Version History

Original
Introduced

  IDL Online Help (March 06, 2007)