The format for this command is:
GOTO LABEL
where LABEL is a line in your batch file that starts with a colon (:) followed by up to an eight
character name (actually, you can type any number of characters, but DOS only recognizes the first
eight).
Want to create an endless loop? GOTO gives you an easy way. Here is one example:
:START
REM...This is being typed by an endless loop.
GOTO START
When executed, this file will continue to print the endless loop line and the GOTO
command until you tap Control-Break.
Use this subcommand to transfer control in your batch files.
If you want to terminate any batch file before it is complete, issue the break command
[Control-Break].
Interim Review
You have now seen the simple stuff...Let's see how much of it stuck. Following are a few
true/false questions. Think of the answer then look below to see if you were right.
Questions:
1. The file AUTOEXEC.BAT must be in the root directory of the boot disk.
2. Batch files can execute a variety of subcommands in addition to the standard DOS commands.
3. Parameters are designated as %0 through %9.
4. When DOS finds a batch subcommand that is improperly phrased, it stops execution of the file
and shows Syntax error.
5. You may interrupt a batch command by pressing Control-Home.
6. When you type Control-Break to stop a batch file, DOS will ask you if you want to terminate. If
you say No the current command will be ignored but the rest will be processed.
7. The batch filename is substituted for marker %0.8. REMark subcommands display a message
regardless of the the condition of ECHO.
9. PAUSE causes the batch file to temporarily stop and wait for you to press a key.
Answers:
1. True, AUTOEXEC.BAT executes automatically when DOS boots so it must be in the root. (A
trick question as it assumes knowledge from prior tutorials. )
2. True, you've seen some, with more to come.
3. False, those are markers. A parameter is information you type in on the command line that is
substituted for a marker when commands are executed.
4. True, we didn't talk about that specifically, but that's what happens.
5. False, the correct command is Control-Break.
6. True, revealing another little quirk of batch file processing.
7. True, but there is a command you can use to change that as we'll see later.
8. False, REM only shows its message if ECHO is ON. If ECHO is OFF, only ECHO puts a
message to the screen.
9. True.
That's enough. You should now understand the batch file subcommands you are likely to
need most often.
Let's move on to the rest of the subcommands that allow you to program within a batch file.
Subcommands in this section are generally used to create batch programs. As such, they are a bit
more complex than the simply ones studied on the last page.
No comments:
Post a Comment