[Toc][Index]

GOSUB - Execute a subroutine in a batch file

 
 Purpose:    Execute a subroutine in the current batch file. 
             
 Format:     GOSUB label 
             
             label :  The batch file label at the beginning of the 
             subroutine. 
 
 See also:  CALL, GOTO and RETURN. 
 Usage 
 GOSUB can only be used in batch files. 
 CMD.EXE allows subroutines in batch files.  A subroutine must start with 
 a label (a colon [:] followed by a one-word label name) which appears on 
 a line by itself.  Case differences are ignored when matching labels. 
  Labels may be one or more words long.  The subroutine must end with a 
 RETURN statement. 
 The subroutine is invoked with a GOSUB command from another part of the 
 batch file.  After the RETURN, processing will continue with the command 
 following the GOSUB command.  For example, the following batch file 
 fragment calls a subroutine which displays the directory and returns: 

 
         echo Calling a subroutine
         gosub subr1
         echo Returned from the subroutine
         quit
         :subr1
         dir /a/w
         return
 
 
 CMD.EXE begins its search for the label on the next line of the batch 
 file (after the GOSUB command).  If the label is not found between the 
 current position and the end of the file, GOSUB will restart the search 
 at the beginning of the file.  If the label does not exist, the batch 
 file is terminated with the error message "Label not found." 
 GOSUB saves the IFF and DO states, so IFF and DO statements inside a 
 subroutine won't interfere with statements in the part of the batch file 
 from which the subroutine was called. 
 Subroutines can be nested. 

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs