Goto
Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2
Goto
Within a batch program, directs command processing to a line identified by a label. When the label is found, processing continues starting with the commands that begin on the next line.
Syntax
goto Label
Parameters
- Label
Specifies the line in a batch program to which you want to go.
- /?
Displays help at the command prompt.
Remarks
Working with command extensions
If command extensions are enabled (that is, the default) and you use the goto 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 goto with the :EOF label, you must insert a colon before the label. For example:
goto :EOF
For a description of extensions to the call command that make this feature useful, see cmd in Related Topics.
Using valid Label values
You can use spaces in the Label parameter, but you cannot include other separators (for example, semicolons or equal signs).
Matching Label with the label in the batch program
The Label value you specify must match a label in the batch program. The label within the batch program must begin with a colon (:). The Windows Server 2003 family 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, any commands on that line are ignored. If your batch program does not contain the label that you specify, the batch program stops and displays the following message:
Label not found
Using goto for conditional operations
You can use goto with other commands to perform conditional operations. For more information about using goto for conditional operations, see if in Related Topics.
Examples
The following batch program formats a disk in drive A as a system disk. If the operation is successful, the goto command directs processing to the :end label:
echo off
format a: /s
if not errorlevel 1 goto end
echo An error occurred during formatting.
:end
echo End of batch program.
Formatting legend
Format | Meaning |
---|---|
Italic |
Information that the user must supply |
Bold |
Elements that the user must type exactly as shown |
Ellipsis (...) |
Parameter that can be repeated several times in a command line |
Between brackets ([]) |
Optional items |
Between braces ({}); choices separated by pipe (|). Example: {even|odd} |
Set of choices from which the user must choose only one |
|
Code or program output |
See Also
Concepts
Call
Cmd
If
Command-line reference A-Z
Command shell overview