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.
To exit a batch script file or exit a subroutine specify GOTO:eof this will transfer control to the end of the current batch file, or the end of the current subroutine.
Examples:
IF %1==12 GOTO MySubroutine
Echo the input was NOT 12
goto:eof
:MySubroutine
Echo the input was 12
goto:eof
Use a variable as a label
CHOICE /C:01 /m choose [Y]yes or [N]No
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 bash command:
case - Conditionally perform a command