Purpose:Return from a GOSUB (subroutine) in a batch file


Format:RETURN [value]


valueThe numeric exit code to return to TCC


See also: GOSUB.




TCC allows subroutines in batch files.


A subroutine begins with a label (a colon followed by one or more words) and ends with a RETURN command.


The subroutine is invoked with a GOSUB command from another part of the batch file. When a RETURN command is encountered the subroutine terminates, and execution of the batch file continues on the line following the original GOSUB. If RETURN is encountered without a GOSUB, TCC will display a "Missing GOSUB" error message.


You cannot execute a RETURN from inside a DO loop.


The following batch file fragment calls a subroutine which displays the files in the current directory:


echo Calling a subroutine

gosub subr1

echo Returned from the subroutine



dir /a/w



If you specify a value, RETURN will set the internal exit code to that value. That exit code should be tested immediately upon return from the subroutine and before it is reset by another command. For information on exit codes from internal commands, see the _? variable.