Previous IDL Reference Guide: Procedures and Functions Next

RETURN

Syntax | Arguments | Examples | Version History | See Also

The RETURN command causes the program context to revert to the next-higher program level. RETURN can be called at the interactive command prompt (see .RETURN), inside a procedure definition, or inside a function definition.

Calling RETURN from the main program level has no effect other than to print an informational message in the command log.

Calling RETURN inside a procedure definition returns control to the calling routine, or to the main level. Since the END statement in a procedure definition also returns control to the calling routine, it is only necessary to use RETURN in a procedure definition if you wish control to revert to the calling routine before the procedure reaches its END statement.

In a function definition, RETURN serves to define the value passed out of the function. Only a single value can be returned from a function.


Note
The value can be an array or structure containing multiple data items.

Syntax

RETURN [, Return_value]

Arguments

Return_value

In a function definition, the Return_value is the value passed out of the function when it completes its processing.

Return values are not allowed in procedure definitions, or when calling RETURN at the interactive command prompt.

Examples

You can use RETURN within a procedure definition to exit the procedure at some point other than the end. For example, note the following procedure:

PRO RET_EXAMPLE, value  
   IF (value NE 0) THEN BEGIN  
      PRINT, value, ' is nonzero'  
      RETURN  
      END  
   PRINT, 'Input argument was zero.'  
END  

If the input argument is non-zero, the routine prints the value and exits back to the calling procedure or main level. If the input argument is zero, control proceeds until the END statement is reached.

When defining functions, use RETURN to specify the value returned from the function. For example, the following function:

FUNCTION RET_EXAMPLE2, value  
   RETURN, value * 2  
END  

multiplies the input value by two and returns the result. If this function is defined at the main level, calling it from the IDL command prompt produces the following:

PRINT, RET_EXAMPLE2(4)  

IDL prints:

8  

Version History

Original
Introduced

See Also

RETALL

  IDL Online Help (March 06, 2007)