Script GOSUB Statement

GOSUB @label

The GOSUB statement is used to branch to a different location (a subroutine) in the script with the option of returning to the statement that follows GOSUB. Subroutines are  useful when an identical set of statements is executed from various points in the script.

GOSUB has only one parameter, a  label. When GOSUB is reached, script processing moves to the indicated label and continues processing until a RETURN statement is reached. The RETURN statement causes the script to continue with the statement following the GOSUB statement.

GOSUBs may be nested up to eight levels.

For example:

ECHO "Right before the GOSUB."
ECHO "Right after the GOSUB."

ECHO "Within the GOSUB."


Right before the GOSUB.
Within the GOSUB.

Right after the GOSUB.

Copyright © 2017 American Chemical Society. All Rights Reserved.