GOTO
Direct a batch program to jump to a labelled line.
Syntax GOTO label
Key
label : a predefined label in the batch program. Each label must be on a line by itself, beginning with a colon.
For example:
IF %1==12 GOTO s_december
:: other commands
:s_december
GOTO :eof
An easy way to exit a batch script file without defining a label is to specify
GOTO :eof
this transfers control to the end of the current batch file.
Using a variable as a label
CHOICE
goto s_routine_%ERRORLEVEL%
:s_routine_0
echo You typed Y for yes
:s_routine_1
echo You typed N for no
Skip commands by using a variable as a ::
comment (REM)
In this example the COPY command will only run if the parameter "Update"
is supplied to the batch
@echo off
setlocal
IF /I NOT %1==Update SET _skip=::
%_skip% COPY x:\update.dat
%_skip% echo Update applied
...
If Command Extensions are disabled GOTO will no longer recognise the :EOF label
"It's just a jump to the left... and then a step to the right.." - The Time Warp
Related Commands:
IF - Conditionally perform a command
CALL - Call one batch program from another
Equivalent Linux BASH commands:
case - Conditionally perform a command