Omni Systems, Inc. Mif2Go User's Guide, Version 55
> 28 Working with macros > 28.6 Using expressions in macros > 28.6.4 Using control structures in expressions > 28.6.4.2 Using conditional expressions
A conditional expression starts with:
<$_elseif (expr)> (as many as you please)
<$_elseif not (expr)> (as many as you please)
<$_else> (evaluated when no expr is true)
<$_endif> (optional if at the end of a macro)
(As an alternative to a long list of <$_elseif>
clauses, you could use an indexed array for the (expr)
values; see §28.4.6 Using a list instead of a conditional expression.)
Result of testing a string value
If (
expr)
has a string value, that value is seen as a non-number, and (
expr)
would evaluate
to zero; that is, false. The relational operators always return “0”
(false) or “1” (true), so if you had a variable $$myword
with yes/no values, you would have to test the value like this:
You cannot nest <$_if>
s
(and <$_if not>
s) in the same macro;
instead, call a second macro from within the first, and include the subordinate
<$_if>
(or <$_if
not>
) in the second macro. You specify a limit to such macro
nesting with the following setting (see §28.1.3 Nesting macros):
Conditionals within expressions
You can also use C-style ternary operators “?
”
and “:
”, for a shorthand
version of a conditional expression. For example:
<$_if ($$myvar)>yes<$_else>no<$_endif>
The ternary operators give you a natural way to use conditionals within an expression, which is otherwise impossible.