logo
Home XtGem- Templates- XtScript- bottom
XtGemmanual

XtScript basics

if

The if statement creates the branches and switches of your Xtscript

Syntax

if ...
...
[else
...]
endif[...] optional · ... your value

Notes

"Nested if's" can be a problem in xtscript ... They do not work and should be avoided
Most of these issues can be overcome using goto

Example

<!--parser:xtscript-->
# random number
var $x = call mt_rand $min=1;$max=100

# The basic "if"
if $x > 50
  print \$x is more than 50 <hr />
else
  print \$x is less than 50<hr />
endif

# Strings can also be compared
var $a=abcdef
var $b=abcdeg
if $a < $b
  print '$a' is less than '$b' <hr />
endif

# if's nested like this will not work
var $a=1
var $b=2
if $a == 3
  if $b == 2
    print \$b equals 2
  endif
  print \$a equals 3 ?<hr />
endif

# Most of the problems with nested "if's" can be overcome using "goto"
if $a == 3
  print \$a equals 3
else
  goto @end 
endif
if $b == 2
  print \$b equals 2
endif
@end
print no output because \$a does not equal 3 so \$b test is skipped 
<!--/parser:xtscript-->

Copy as text

Output reload

$x is less than 50
'abcdef' is less than 'abcdeg'
$a equals 3 ?
no output because $a does not equal 3 so $b test is skipped

Related

if and if or
if not or if not or not if elseif goto

XtGem manual · all sections

Powered by XtGem
About us Contact Forum top