XtGem Forum catalog
/ /

XtScript: Comparison - Logical Operators

Learn how to use logical operators in XtScript to create dynamic output of your code

Comparison operator is used to compare and evaluate of two different variable.

Comparison operator is mainly useful in the XtScript conditional operation.

XtScript Comparison Operators
OperatorSyntax exampleSummary
==$a == $bReturn true if the variable $a and $b are: "Equals to", "Same with", "Has same value with".
!=$a != $bReturn true if the variable $a and $b are: "Not equals to", "Not same with", "Has different value with".
>$a > $bReturn true if variable $a has greater value to $b.
>=$a >= $bReturn ture if variable $a has greater value or equals to $b
<$a < $bReturn true if variable $a has less value than $b
<=$a <= $bReturn true if variable $a has less value or equals to $b

Learn XtScript Comparison Operators from examples

Compare a variable contains number and make different output based on different conditions.

- Code:
<!--parser:xtscript-->
	var $cash = 7000

	if $cash <= 1000
		print You have $cash USD. You are such a poor Man
	elseif $cash <= 10000
		print You have $cash USD. You are just a regular Man
	elseif $cash > 10000
		print You have $cash USD. Wow you are a rich Man
	else
		print You don't have any money?
	endif
<!--/parser:xtscript-->
- Result:
You have 7000 USD. You are just a regular Man
Compare a variable contains string and make different output based on different conditions.

- Code:
<!--parser:xtscript-->
	var $popular = Android
	var $own = iOS
	if $popular == $own
		print <p>You have $own? You are using the most popular phone in the world.</p>
	else
		print <p>You have $own? It is not the most popular phone</p>
	endif

	# Re-declared $own variable then run the same if command with exact same conditions and arguments
	var $own = Android
	if $popular == $own
		print <p>You have $own? You are using the most popular phone in the world.</p>
	else
		print <p>You have $own? It is not the most popular phone</p>
	endif
<!--/parser:xtscript-->
- Result

You have iOS? It is not the most popular phone

You have Android? You are using the most popular phone in the world.