The if operator switches execution of the script depending on the value of a boolean argument:
if statement. 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!
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 <zs:not <zs:strcmp s "hello">>
echo "Hello to you too!"
else
if <zs:not <zs:strcmp s "goodbye">> // note if is nested inside else
echo "Farewell!"
endif
endif
The output of which is:
Farewell!