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 ), 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.
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:
PRINT, 'Input argument was zero.'
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:
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: