[Toc][Index]

GOTO - Branch within a batch file

 
 Purpose:    Branch to a specified line inside the current batch file. 
             
 Format:     GOTO [/I] label 
             
             label :  The batch file label to branch to. 
             
             /I(FF and DO continue)          
 
 See also:  GOSUB. 
 Usage 
 GOTO can only be used in batch files. 
 After a GOTO command in a batch file, the next line to be executed will 
 be the one immediately after the label.  The label must begin with a 
 colon [:] and appear on a line by itself. The colon is required on the 
 line where the label is defined, but is not required in the GOTO command 
 itself.  Case differences are ignored when matching labels.  Labels may 
 be one or more words long. 
 This batch file fragment checks for the existence of the file CONFIG.SYS. 
  If the file exists, the batch file jumps to C_EXISTS and copies all the 
 files from the current directory to the root directory on A:.  Otherwise, 
 it prints an error message and exits. 

 
         if exist config.sys goto C_EXISTS
         echo CONFIG.SYS doesn't exist - exiting.
         quit
         :C_EXISTS
         copy *.* a:\
 
 
 
 GOTO begins its search for the label on the next line of the batch file 
 (after the GOTO command).  If the label is not found between the current 
 position and the end of the file, GOTO 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." 
 To avoid errors in the processing of nested statements and loops, GOTO 
 cancels all active IFF statements and DO / ENDDO loops unless you use /I. 
  This means that a normal GOTO (without /I) may not branch to any label 
 that is between an IFF and the corresponding ENDIFF or between a DO and 
 the corresponding ENDDO. 
 For compatibility with Windows NT's CMD.EXE, the command 

 
         GOTO :EOF
 
 
 will end processing of the current batch file if the label :EOF does not 
 exist.  However, this is less efficient than using the QUIT or CANCEL 
 command to end a batch file. 
 Options 
    /I:     (IFF and DO continue) Prevents GOTO from canceling IFF 
            statements and DO loops.  Use this option only if you are 
            absolutely certain that your GOTO command is branching 
            entirely within any current IFF statement and any active DO / 
            ENDDO block.  Using /I under any other conditions will cause 
            an error later in your batch file. 
            You cannot branch into another IFF statement, another DO loop, 
            or a different IFF or DO nesting level, whether you use the /I 
            option or not.  If you do, you will eventually receive an 
            "unknown command" error (or execution of the UNKNOWN_CMD 
            alias) on a subsequent ENDDO, ELSE, ELSEIFF, or ENDIFF 
            statement. 
 

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