|
Directs Windows to a labelled line in a batch program.
Syntax:
GOTO label
GOTO:label
| label | The line in a batch file to which execution should branch.
label must match a label in the batch program or the batch program stops and an error message is displayed. |
Notes:
- A batch file label is a text string, on a line of its own and beginning with a colon.
- Although there are few restrictions on the make up of a label, GOTO is the only command to use labels and imposes its own rules:
- GOTO only recognises the first 8 characters in the first word of the label. Subsequent characters and/or words are ignored. Thus, the labels "hithere01" and "hithere02" are both equivalent to "hithere0".
- GOTO looks for the first instance of a label to match label starting from the beginning of the batch file - NOT from where it is called. Thus, using the above example, "hithere02" will never be called.
- GOTO treats a colon (:) as a space. Thus "GOTO step1", "GOTO:step1", "GOTO: step1" and "GOTO :step1" are all treated as equivalent.
This can be useful when passing a GOTO command as an arguement in a batchfile: GOTO:step1 would be passed as a single arguement whereas GOTO step1 would have to be passed as two.
Example:
To format a disk in drive A and display an appropriate message of success or failure:
@ ECHO off
FORMAT a: /s
IF NOT errorlevel 1 GOTO end
ECHO An error occurred during formatting.
:end
ECHO Successfully formatted the disk in drive A.
File Details:
Internal
|