Batch Files

Batch Files

Sections: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Index | Next >

GOTO Command (Internal)

Learning objective: (2) Explain the use of the GOTO command and labels in batch files


Click on image to enlarge.

The GOTO command allows the normal sequencing of events to jump to other locations in the batch file, either above or below the current location. If the jump is above the current location, the jump provides looping. If the jump is below the current location, the jump provides selection. A :label is the location of the jump. A label is any text, with no spaces, that starts with a colon like ":end". (Spaces act as delimiters.) In the event a batch file ends with an endless loop, you can use "Crtl+C" to stop the loop.

This batch file will generate an endless loop. When the batch file reaches the bottom, the GOTO command sends it to the loop label.

:label

The :label is a marker in the batch file that a GOTO command can jump to. The GOTO jump can either jump up to create looping or jump down for selection. During execution, if a :label is encountered, no action will be taken and processing will continue to the next line. It is good form to have a ":end" section at the bottom of the batch file to act as a termination point for the batch file.

GOTO label

GOTO label (note the reference to the label does NOT start with a ":" colon) will jump to that location in the batch file. If one is not careful, an endless loop can be created. If that occurs, a "Ctrl+C" should stop the runaway loop.

Thinking: What is the functional difference between jumping up or jumping down from a given location in the batch file?

Key terms: GOTO, end, endless loop, label

Resources:
To maximize your learning, please visit these Web sites and review their content to help reinforce the concepts presented in this section.

Quick links:
GOTO @ ss64.com
GOTO command @ instructables.com

Embedded Resources

Notes on navigation: Click inside the frame to navigate the embedded Web page. - Click outside the frame to navigate this page to scroll up/down between the embedded Web pages. - Click on the frame title to open that page in a new tab in most browsers. - Click on the the "Reload page" link to reload the original page for that frame.

GOTO @ ss64.com | Reload page | If frame is empty, click on the link to view the page in a new tab or window

GOTO command @ instructables.com | Reload page | If frame is empty, click on the link to view the page in a new tab or window

Sections: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Index | Next >