NT Syntax


Direct a batch program to jump to a labelled line.

      GOTO label 
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

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

goto s_routine_%ERRORLEVEL%

echo You typed Y for yes

echo You typed N for no

Skipping commands by using a variable as an optional :: (REM) comment

In this example the 2 COPY commands will only run if the parameter "Update_Now" is supplied to the batch

@echo off
IF [%1]==[] GOTO :eof
IF /I NOT %1==Update_Now SET v_skip=::

%v_skip% COPY x:\update.dat
echo Your WWW connection is up to date

%v_skip% COPY x:\FTP.dat
echo Your FTP connection is up to date

Related Commands:

IF -

If Command Extensions are disabled GOTO will no longer recognise the :EOF label

Equivalent Linux BASH commands:

case - Conditionally perform a command

Simon Sheppard