Direct a batch program to jump to a labelled line.

      GOTO label


   label   A predefined label in the batch program.
           Each label must be defined on a line by itself, beginning with
           a colon and ending with either a space, a colon or a CR/LF.

   :eof    This predefined label will exit the current routine.

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. Unlike Exit /b the goto:eof will automatically set an errorlevel.


IF %1==12 GOTO MySubroutine
Echo the input was NOT 12

Echo the input was 12

Use a variable as a label

CHOICE /C:01 /m choose [Y]yes or [N]No
goto s_routine_%ERRORLEVEL%

Echo You typed Y for yes

Echo You typed N for no

Use a variable as a comment
In this example the COPY command will only run if the parameter "Update" is supplied to the batch

@echo off
IF /I NOT %1==Update SET _skip=::

%_skip% COPY x:\update.dat
%_skip% echo Update applied

GOTO is an internal command. If Command Extensions are disabled GOTO will no longer recognise the :EOF label

“GOTO... how bad can it be??...” ~ XKCD


EXIT - Quit the current script/routine and set an errorlevel.
IF - Conditionally perform a command.
CALL - Call one batch program from another.
Powershell: While (condition) {action} else {action}
Equivalent bash command: case - Conditionally perform a command.

© Copyright 1999-2013
Some rights reserved