This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Directs cmd.exe to a labeled line in a batch program. Within a batch program, this command directs command processing to a line that is identified by a label. When the label is found, processing continues starting with the commands that begin on the next line.
goto <label>| Parameter | Description |
|---|---|
<label> | Specifies a text string that is used as a label in the batch program. |
| /? | Displays help at the command prompt. |
If command extensions are enabled (the default), and you use thegoto command with a target label of:EOF, you transfer control to the end of the current batch script file and exit the batch script file without defining a label. When you use this command with the:EOF label, you must insert a colon before the label. For example:goto:EOF.
You can use spaces in thelabel parameter, but you can't include other separators (for example, semicolons (;) or equal signs (=)).
Thelabel value that you specify must match a label in the batch program. The label within the batch program must begin with a colon (:). If a line begins with a colon, it's treated as a label and any commands on that line are ignored. If your batch program doesn't contain the label that you specify in thelabel parameter, then the batch program stops and displays the following message:Label not found.
You can usegoto with other commands to perform conditional operations. For more information about usinggoto for conditional operations, see theif command.
The following batch program formats a disk in drive A as a system disk. If the operation is successful, thegoto command directs processing to the:end label:
echo offformat a: /sif not errorlevel 1 goto endecho An error occurred during formatting.:endecho End of batch program.Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?