XtScript: Conditional Operators
Learn how to make different output of your XtScript code based on conditional arguments given
Conditional operators is a way to make a dynamic output of our XtScript codes based on the certain conditions included.
If you are familiar with conditional operator in Javascript or PHP, you will not find hard time in learning conditional operators in XtScript.
Conditional operation in XtScript is begin with if and closed with endif.
XtScript Conditional Operators | |
---|---|
Command | Syntax |
if | if condition # Code to be executed if condition true endif |
if .. else .. | if condition # Code to be executed if condition true else # Code to be executed if condition false endif |
if .. elseif .. else | if condition # Code to be executed if condition true elseif condition 2 # Code to be executed if first condition false and condition 2 true else # Code to be executed if all condition false endif |
Learn XtScript Conditional Operators from examples
XtScript if
- Code:
- Code:
<!--parser:xtscript--> var $fruit = Banana if $fruit == Apple print I have an Apple endif print <p>The print command inside <b>if</b> is not been executed because \$fruit value is not Apple, but Banana</p> <!--/parser:xtscript-->- Result:
The print command inside if is not been executed because $fruit value is not Apple, but Banana
XtScript if .. else
- Code:
- Code:
<!--parser:xtscript--> var $fruit = Banana var $question = Do you have an Apple? if $fruit == Apple print $question Yes, I have an Apple else print $question No, I only have $fruit endif <!--/parser:xtscript-->- Result:
Do you have an Apple? No, I only have Banana
XtScript if .. elseif .. else
- Code:
- Code:
<!--parser:xtscript--> var $money = 1000 if $money < 500 print <p>I have $money USD. I can not buy a new smartphone</p> elseif $money > 500 print <p>I have $money USD. I can buy a new smartphone</p> else print I dont' have any money endif <!--/parser:xtscript-->- Result:
I have 1000 USD. I can buy a new smartphone
Last edited on