Goto command

Updated: 11/12/2023 by Computer Hope
goto command at a command line.

The goto command moves a batch file to a specific label or location, enabling a user to rerun it or skip other lines depending on inputs or events.

Availability

Goto is an internal command that is available in the following Microsoft operating systems.

Goto syntax

GOTO label
label Specifies a text string used in the batch program as a label.

You type a label on a line by itself, beginning with a colon.

Windows 2000, Windows XP, and later additional syntax

If Command Extensions are enabled, GOTO changes as follows:

GOTO command now accepts a target label of :EOF that transfers control to the end of the current batch script file, which exits without defining a label. Type CALL /? for a description of extensions to the CALL command that make this feature useful.

Goto examples

In the example below, the batch file would only print "DONE," skipping anything that is between the GOTO and the GOTO target label.

GOTO END
ECHO SKIPPING THIS
:END
ECHO DONE