SYNOPSIS<IF condition1>
... statements if condition1 true ...
[<ELSE[ ]IF condition2>
... statements if condition2 true ...]
[<ELSE>
... statements if both are false ...]
</IF>
DESCRIPTION
The IF
statement evaluates the given conditional expression.
If the result is true (i.e. nonzero), then the statements following the
<IF>
tag are executed. If the result is false, those statements are
skipped and control falls to the next statement after the closing
</IF>
tag.
An optional ELSE
clause may be present, in which case the
statements following the <ELSE>
tag are executed instead if the
result is false. If the ELSE
clause is another IF
statement, it can be made part of the <ELSE>
tag by using
<ELSEIF>
. Thus, the left and right statements below are equivalent:
<IF $x eq 5> <IF $x eq 5>
X is five. X is five.
<ELSE> <ELSEIF $y gt 10>
<IF $y gt 10> Y is greater than 10.
Y is greater than 10. <ELSE>
<ELSE> X is not five and Y is <= 10.
X is not 5 and Y is <= 10. </IF>
</IF>
</IF>
If many ELSEIF
clauses are used on the same value, a SWITCH
statement (here) may be a clearer alternative.
The condition of an IF
statement can be simple or complex. A
simple condition is of the form arg1 op arg2, where each
arg is a variable or literal string, and op is one of the
following operators:
eq
or =
: Equalsne
or neq
: Does not equalgt
: Greater thange
or gte
: Greater than or equal tolt
: Less thanle
or lte
: Less than or equal tonmod
: Not mod; true if value1
mod value2
is 0
For example:
<IF $temp lt 32>
Ice
<ELSE>
Water
</IF>
A SQL expression condition can be any valid Texis SQL WHERE
clause. Thus, and
and or
may be used, or even
like
:
<IF $limit lt 5 and ($ans eq "correct" or $body like $query)>
You're under the limit, and either
have the correct answer or the text matches your query.
</IF>
CAVEATS
Variables should not be embedded inside a literal string,
e.g. "this is a $test"
. Literal string values should always be
quoted, or they may be misconstrued as non-existent SQL columns.
The results of some operators can depend on the original type of the values, e.g. comparison of integer vs. string values (see discussion under Variable Types, here).
If a variable contains more than one value in its current context
(i.e. outside a LOOP
), only the 0th (first) value is used.
An empty (no values) variable is considered an empty string.
SEE ALSOSWITCH