Flow of control, Conditional branches, Looping command – Nisus Writer Pro User Manual
Page 424

404
The Nisus Writer Pro Macro Language
Flow of control
Conditional branches
Very simple conditionals are supported in the menu command dialect. The following is the
if!construct:
If expression1
code1
elsif expression2
code2
...
elsif expressionN
codeN
else
codeFinal
end
Explained in English:
If “expression1” is true, then do “code1”.
If it is false (“elseif”) check to see if there is an “expression2” and possibly do “code2” (or
some other task “expressionN”.
Or “else”, if no expression matches, do “codeFinal”.
All the blocks are optional.
The Boolean equality testing operators are the same as those that Perl uses for numeric values.
Therefore Nisus Menu Command Dialect must implicitly distinguish between numeric compares
and string compares. Thus if both strings are numbers, comparison is numeric, otherwise it is
string comparison. In the menu command dialect:
==
checks to see if the two values are equal
!=
checks to see if the two values are not equal
<
means less than
<=
means less than or equal to
>
means greater than
>=
means greater than or equal to
If either value given to the operator is a string, then a case sensitive string comparison is made.
Here's an example:
$name = Prompt Options "What is your name?", "", "OK", "Bob", "Greg",
"Dan", "Victor"
if $name == "Bob"
Prompt "Hello Bob."
elsif $name == "Greg"
Prompt "Hello Greg."
else
Prompt "Never heard of you."
end
There is one limitation on the binary operators: they can only operate on variables and literal
values, not directly on command return values. For instance, these are legal:
$isTrue = 3
>
1
$isEqual = $name == "Whatever"
But this is illegal:
$isTrue = "Bob" == Prompt Input "What is your name?"
Looping command
While expression
loop body
End
As long as expression is a true value (defined just as in Perl, that is any non-zero value is true, all
others are false including zero or an empty value) the loop body will continue to execute
repeatedly. An example macro that will toggle the superscript of all note references in the
document: