Conditional commands are different from other Enforcer Script commands in that they operate together, rather than independently. It's easiest to use examples to show the various options.
The simplest conditional is the !exitif command.
Syntax:
!exitif <expression>
Example:
!exitif $finished
Description:
This is used to conditionally terminate a program or subprogram (a notecard invoked via @ or &). It takes a single argument, which is evaluated as an expression, and if the result, when evaluated as a boolean, is "true", then execution of the current notecard will be terminated, just as if the end of the notecard had been reached.
There is a special version of the !exitif command - !exit - that is equivalent to !exitif true. In other words, it exits the current notecard unconditionally.
There is an implicit !exit at the end of every notecard.
More complex conditional programming can use the !if, !else and !fi commands. These operate together.
!if starts a conditional block, which must end with a matching !fi within the same notecard. There may optionally be one !else between !if and !fi. So the following are valid conditional blocks:
In the above, <then-part> and <else-part> consist of one or more instruction lines. If the argument to !if ($expression in this case) evaluates to "true", then the instructions in <then-part> are executed; if not, then the instructions in <else-part>, if it exists, are executed.
Both <then-part> and <else-part> may contain nested conditional blocks of their own.
No comments:
Post a Comment