Home > Commands A-M > Batch G


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Directs the operating system to a line in a batch program that is marked by a label you specify. You can use this command only in batch programs.

The GOTO command directs within a batch program to a line identified by a label. When the label is found, it processes the commands beginning on the next line.



GOTO [:]label

[:]label (v2.0 Win95 NT3.5)
Specifies the line in a batch program to go. Colon (:) is treated as space.

/? (NTXP)
Display help.


Equivalent Linux BASH commands:
case - Conditionally perform a command.

GOTO :eof as the end of the batch file

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.

Valid values for label

The label parameter cannot include separators such as spaces, semicolons or equal signs.

GOTO uses the first eight characters of each label

The GOTO command uses only the first eight characters of a label. Therefore, the labels 'hithere01' and 'hithere02' are both equivalent to 'hithere0'.

If two labels are the same (or just have the same first eight characters), the first label from the top of the BATCH file will be where processing will continue.

Matching the label parameter with the label in the batch program

The label value you specify on the GOTO command-line must match a label in the batch program. The label within the batch program must be preceded by a colon.

If your batch program does not contain the label that you specify, the batch program stops and the operating system displays the message:

    Label not found

The operating system recognizes a batch-program line beginning with a colon (:) as a label and does not process it as a command. If a line begins with a colon, the operating system ignores any commands on that line.

Using GOTO for conditional operations

GOTO is often used on the same command-line with other commands to perform conditional operations. For more information about using GOTO for conditional operations, see the IF command.


This batch program formats a disk in drive A as a system disk. If the operation is successful, the GOTO command directs the operating system to a label named 'end'.

     FORMAT A: /S
      ECHO An error occurred during formatting.
      GOTO END
      ECHO Successfully formatted the disk in drive A.



v2.0 v2.01 v2.05 v2.10 v2.11 v2.11R v2.12 v2.2 v2.25 v3.0 v3.20 v3.05 v3.1 v3.21 v3.25 v3.30 v3.3A v3.3R v3.3T v3.31 v3.40 v4.0 v4.01 v4.01A v5.0 v5.0A v5.00.02 v5.001A v5.01 v5.02 v6.0 v6.10 v6.2 v6.21 v6.22 v6.23 v7.00 v7.0R1 v7.10 v8.00
Win95 Win98 WinME
Windows NT
NT3.5 NT4 NT2000 NTXP NT2003