Subroutines in Batch Commands
Most mature high-level programming languages allow you to build common routines into independent modules, namely subroutines, which preserve the independence of the code, standardize the program, and facilitate organization. At the very least, it can be said that DOS batch commands do not fully support subroutines, but you can always use the GOTO command to call a subroutine.
Usually, the label used by the GOTO command can also accept a label stored in an environment variable, for example:
SET LABELNAME=START
GOTO %LABELNAME%
By replacing the label at the beginning of the subroutine and setting the GOTO %RETURN% statement at the end of the subroutine, you can build subroutines in DOS batch commands. As long as you SET an environment variable RETURN, you can call the subroutine at any point in the batch command. For example, you can assign a value to the label and call the subroutine on the next line, then the GOTO statement jumps to the beginning of the subroutine. The program structure is as follows:
REM This set the environment
REM variable and calls the
REM subroutine
SET RETURN=HERE
GOTO SUB
HERE
SUB
REM
Place subroutine statements
REM below
GOYO %RETURN%
The statement GOTO SUB transfers to the subroutine SUB, where you can execute any statements. When executing to GOTO %RETURN%, the batch command returns control to the label HERE because the environment variable RETURN is reassigned to HERE. If you use a unique label (such as RETURN) each time you call SUB, you can call SUB multiple times in multiple places.
Most mature high-level programming languages allow you to build common routines into independent modules, namely subroutines, which preserve the independence of the code, standardize the program, and facilitate organization. At the very least, it can be said that DOS batch commands do not fully support subroutines, but you can always use the GOTO command to call a subroutine.
Usually, the label used by the GOTO command can also accept a label stored in an environment variable, for example:
SET LABELNAME=START
GOTO %LABELNAME%
By replacing the label at the beginning of the subroutine and setting the GOTO %RETURN% statement at the end of the subroutine, you can build subroutines in DOS batch commands. As long as you SET an environment variable RETURN, you can call the subroutine at any point in the batch command. For example, you can assign a value to the label and call the subroutine on the next line, then the GOTO statement jumps to the beginning of the subroutine. The program structure is as follows:
REM This set the environment
REM variable and calls the
REM subroutine
SET RETURN=HERE
GOTO SUB
HERE
SUB
REM
Place subroutine statements
REM below
GOYO %RETURN%
The statement GOTO SUB transfers to the subroutine SUB, where you can execute any statements. When executing to GOTO %RETURN%, the batch command returns control to the label HERE because the environment variable RETURN is reassigned to HERE. If you use a unique label (such as RETURN) each time you call SUB, you can call SUB multiple times in multiple places.
我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
