Flow Control |
14.1
The order in which commands in a macro are executed is sometimes
called the "flow" of
the macro. Usually when a macro is played, the macro commands
are executed in order, from
the beginning of the macro to the end. But there are occasions
when you will want to change the
flow of the macro, for example by skipping certain commands when
some condition exists. Of you may wish to have two "branches" of
flow in the macros, depending on a decision. You might also want
to end the macro prematurely (before all the commands are
executed).
|
| Label(name) |
where "name" is any identifier you want to use as the name for the location.
A Label() command can be inserted anywhere in
the macro.
It does nothing but mark a location. You can have as many labels
as you need
in a macro, but of course each label must have a separate name.
You should
follow the same rules in naming labels as for naming variables.
To readily
identify labels, the "@" character is sometimes added to the end
of label
names.
The
Go() command
The form of the GO() command is
| Go(name) |
When this command is executed, the macro immediately jumps to the point in the macro program labeled with that name, and continues execution from that point.
You should use go GO() commands sparingly;
they make it
difficult to follow the flow of the macro during editing or
debugging. This
command is PerfectScript's equivalent of the "goto" statement in
other
languages, whose use is considered a bad programming practice.
If
you find
yourself using the Go() command frequently, you
should
familiarize yourself with the Call() command,
which enables a
technique known as structured programming. Structured
programming
is beyond the
scope of this tutorial.
The
Quit command
You will often need to use the Quit() command if you jump to a different location in the macro. Remember that a Label() simply marks a location in the macro. This means that the commands after the label are part of the macro, and will be executed as part of the normal flow of the macro, even if you don't jump to the label. If you want to avoid this, insert a Quit command before the label. Then those commands will be executed only if you jump to the label with a Go() command.
© 1999 Seth H. Katz
All rights reserved
E-MAIL TO AUTHOR
![]() |
![]() |
![]() |