If true

Purpose: Conditional statement.

 if-true <condition>
     <any code>
 [
 else-if <condition>
     <any code>
 ] ...
 [
 else-if
     <any code>
 ]
 end-if

where <condition> is:
 ( <comparison> [ and <comparison> [ , ... ] ] )
 |
 ( <comparison> [ or <comparison> [ , ... ] ] )

<comparison> is for strings:
 <string> \
    ( equal | not-equal | \
    lesser-than | lesser-equal | \
    greater-than | greater-equal | \
    contain | not-contain ) \
 <check string> \
  [ case-insensitive ] [ length <length> ]

<comparison> is for numbers
 <number> \
    ( equal | not-equal | \
    lesser-than | lesser-equal | \
    greater-than | greater-equal | \
    every | not-every ) \
 <check number>  ...

<comparison> is for booleans:
 <boolean> ( equal | not-equal ) <check boolean>  ...

if-true will evaluate a <condition> and execute code associated with the match. If the <condition> in if-true or "else-if" succeeds, then <any code> below is executed. If it is not a match, then the next condition in "else-if" statement is evaluated, one by one until a match is found and code under that statement executes. If no match is found, then code under "else-if" statement without a <condition> executes (if specified), otherwise program control passes outside of "end-if".

A <condition> is made of one or more <comparison>s, connected by either "and" or "or" clause, but not both in the same <condition>. "and" clause uses logical AND to connect <comparisons> and it succeeds if all <comparison>s succeed. "or" clause uses logical OR to connect <comparisons> and it succeeds if at least one <comparison>s succeeds (if such a <comparison> is found, the following ones are not checked).

Each <comparison> examines either a string, a number or a boolean variable.
String variable in a comparison
If "equal", "not-equal", "lesser-than", "lesser-equal", "greater-than" or "greater-equal" clause is used, a comparison succeeds if <string> is equal, not equal, lesser, lesser or equal, greater or greater-or-equal than <check string>, respectively. If "contain" or "not-contain" clause is used, a comparison succeeds if <string> is contained or not contained in <check string>, respectively. If "case-insensitive" clause is used, a comparison is performed without case sensitivity. If "length" clause is used, only the first <length> bytes of the strings are compared.
Number variable in a comparison
If "equal", "not-equal", "lesser-than", "lesser-equal", "greater-than" or "greater-equal" clause is used, a comparison succeeds if <number> is equal, not equal, lesser, lesser or equal, greater or greater-or-equal than <check number>, respectively.

If "every" is used, then the comparison succeeds if the modulo of <number> and <check number> is 0 - this is useful in executing some code every N times but not the ones in between; with "not-every" the comparison success is this modulo is not 0 which is useful to execute code all the times except every Nth.
Boolean variable in a comparison
If "equal" or "not-equal" clause is used, a comparison succeeds if <boolean> is equal or not equal than <check boolean>, respectively.
else-if without a <condition>
With a given if-true, there can be only one "else-if" statement without a condition, and it must be the last one.
Nesting
if-true can be nested, which can be up to 30 levels deep.
Examples
 %% /if-test public
     get-param inp

     if-true inp equal "1"
         @Found "1" in input
     else-if inp equal "2"  or inp equal "3"
         @Found "2" or "3" in input

         get-param inp_num
         string-number inp_num to num
         if-true num equal 4
             @Found 4 in more input
         else-if num equal 5  and  inp equal "4"
             @Found 5 in more input and "4" in input
         else-if
             @Something else
         end-if

     else-if
         @Found something else
     end-if
 %%

See also
Program flow
break-loop  
code-blocks  
continue-loop  
do-once  
exit-handler  
if-defined  
if-true  
set-bool  
start-loop  
See all
documentation


Copyright (c) 2019-2024 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.