Command : If


Syntax


IF ( < boolean-expression > ) < command 1 > [ [;] else < command 2 > ]

Description


The if command is the main conditional command in kvirc.
if < boolean-expression > evaluates to true < command 1 > is executed,
otherwise (if given) < command 2 > is executed.
The < boolean-expression > is assumed to be 'false' if the result of 'calculations' in that expression is 0 , $_null , $_false or an empty string.; every other result evaluates to 'true'.
The boolean expression can contain boolean operators: ! , & , |.
! = LOGICAL UNARY NOT
& = LOGICAL BINARY AND
| = LOGICAL BINARY OR
Note that the NOT operator in kvirc applies to the result of the following block of operands , so
( !$_false | $_true ) will evaluate to false and
( $_true | !$_false) will evaluate to true,
Just because the first one is parsed as ( ! ($_false | $_true) ) and the second one as ( $_false | (! ($_true) ) ).
Use parenthesis to override the precedence of operators.
( (!$_false) | $_true ) will evaluate to true
Complex boolean expressions can be enclosed in parenthesis.
There MUST be a < SPACE > between the if command and the parenthesis.

Example


/IF ( $_true ) echo $_window Evaluates to true.
/IF ( $_null ) echo $_window Never executed ; else echo $_window Evaluates to false.
/IF ( test ) echo $_window Evaluates to true.
/IF ( !$_null ) echo $_window Evaluates to true.
/IF ( $_true | $_false ) echo $_window Evaluates to true.
/IF ( !$_false & $_true ) echo $_window Evaluates to true.
/IF ( ( $_false | true ) & !$_false) echo $_window Evaluates to true.
/IF () echo $_window Never executed ; else echo $_window Evaluates to false.
/IF (!) echo $_window Evaluates to true ; else echo $_window Never executed.
/IF ( ( $_true | $_false ) & ( !true | false ) )<
    echo $_window This expression;
    echo $_window Evaluates to true;
> else <
    echo $_window This expression;
    echo $_window Evaluates to false;
> ;

See also


WHILE FOREACH
Index  Command list  Commandline syntax