====== if/else/endif ======
The ''if'' operator switches execution of the script depending on the value of a boolean argument:
* If the argument is true, control passes to the line following the ''if'' statement.
* If the argument is false, control passes to the line following the next ''else'' or ''endif'' statement.
The function of ''if'', ''else'' and ''endif'' are demonstrated below:
// create a new boolean value, and set it to true
bool b
set b true
// test value of 'b', and echo value to event log
if b
echo "b is true!"
else
echo "b is false!"
endif
The output of which is:
b is true!
===== Closure and nesting =====
Each ''if'' statement must be closed by a matching ''endif'' statement, and may contain one ''else'' statement. Chains of if/else statements must be nested (unlike C/C++), as shown below:
// create a new string value, and use it to compare in if/else chain
string s
set s "goodbye"
// test value of 's', and reply accordingly
if >
echo "Hello to you too!"
else
if > // note if is nested inside else
echo "Farewell!"
endif
endif
The output of which is:
Farewell!