6.3.1 If clause
Conditional clauses
contain a condition
and parts that are performed if the condition is true (‘then’ part)
and parts that are performed if the condition is false (‘else’ part,
optional). The following table summarizes the available comparison
operators.
|
Operator
|
Semantics
|
|
=
|
Equal to. Comparison is case-sensitive and alphabetic by
default; add num for comparing strings
as numbers, e.g.
id = '3' num.
|
|
=~
|
Matches wildcard: similar to
= but allows the use of wildcards
* (0 to many characters) and
# (1 character) on the right side of
the comparison. Comparison is case-insensitive.
|
|
=/
|
Matches regular expression : similar to
= but allows the use of regular expressions on the right side of the comparison.
Comparison is case-sensitive.
|
|
<>
|
Not equal to. Comparison is case-sensitive and alphabetic by
default; add num for comparing strings
as numbers, e.g.
id <> '3' num
|
|
< and
<=
|
Less than, less than or equal to. Comparison is case sensitive
(A<a) and alphabetic by default; add
num for comparing strings as numbers,
e.g.
id < '3' num
|
|
> and >=
|
Greater than, greater or equal to. Comparison is case
sensitive (a>A) and alphabetic by default; add
num for comparing strings as numbers,
e.g. id > '3'
num
|
The ‘not’ keyword can be used before the condition
to reverse it. There is a possibility to test whether a unary condition is true
or false by giving only the value to test and leaving the condition and other
value out. In this case the true part will be performed if the first value is
not empty: unary tests can also be reversed by adding
not before the value. Boolean
properties can also be used as unary tests.
The left and right side of the condition can be either a
simpleClause (e.g. id), a chainClause
(e.g. :propertyName,
>Transition:Name,
explosions), a literal string (e.g.
'java1.0'), a short-form variable
reference (e.g. $counter), or a
short-form subgenerator call (e.g.
_myCheck()).
This example shows how a property value is
tested:
if :property = 'value' then
/* commands executed when true */
else
/* commands executed when false */
endif
More complex conditions can be expressed using
parentheses and the Boolean operators
not,
and, and
or (in that order of
precedence):
if not (:property1 = 'valueA'
and :property2 = 'valueB')
or (:property3 = 'valueC'
and :property4 = 'valueD')
then
/* commands executed when true */
else
/* commands executed when false */
endif
Note that:
 | and
has higher precedence than or: the
condition c1 or c2 and c3 is equal to
c1 or (c2 and
c3). |
 | not
can be used in a condition at different levels: if
not(not cond1 or not
cond2) |
 | you
can use parentheses to improve the readability of a complex
condition |
 | and
and or do not currently shortcut: all
parts of a condition are evaluated (this may change in a future version, so do
not rely on
it). |