RETURN        Return from a called script file or function

Top  Previous  Next

Syntax:

RETURN

[ retcode ]

Arguments:

[ retcode ]

Optional Variable or numeric value specifying a function return code (valid only within a function body).

Options:

None

 

 

 

This script command is used to exit from a called script file or from a function, and resume script execution at the next command from the point of the call.

 

If the RETURN command appears in a main script (i.e., a script that is not called from another script) or a chained to script (see CALL and CHAIN), then its behavior is identical to the STOP script command.

 

Use of the RETURN command is not always required. For example, it is not required in the following case.

 

BEGINFUNCTIONS

FUNCTION MyFunction

;; body of MyFunction

RETURN

ENDFUNCTION

ENDFUNCTIONS

 

When there are no more script commands in a function to execute, the RETURN command is assumed as shown below.

 

BEGINFUNCTIONS

FUNCTION MyFunction

;; body of MyFunction

ENDFUNCTION

ENDFUNCTIONS

 

This also applies to called script files. At the end of file of a called script file, a RETURN is assumed.

 

When used to return from a function, an optional parameter permits there to be a return code from the function. The returned value may be tested using any of the IFERROR script commands and is saved in the %lasterror script variable. The return code must be numeric otherwise a return code = 0 is assumed. The following is an example of testing for a function return code equal to 1.

 

FUNCTION MyFunction

;; body of MyFunction

RETURN 1

 

;; call the function

MyFunction

IFERROR 1 GOTO function_ok

 

In complicated called script files or functions, multiple return points may be desired. For example, the RETURN command may be used as shown in the rather sloppily written function below.

 

BEGINFUNCTIONS

FUNCTION MyFunction afile

:top

RCVFILE afile

IFERROR= $ERROR_SUCCESS GOTO success

;; return on error

RETURN

:success

MESSAGEBOX "a file received"

ASK "Receive again?" "Question"

IFYES goto top

RETURN

ENDFUNCTION

ENDFUNCTIONS

 

Related Command(s): BEGINFUNCTIONS, ENDFUNCTION, ENDFUNCTIONS, FUNCTION