To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE Programming Environment documentationIf statements

If statements do one thing if the condition is satisified, or do another thing if it is not. They are the most basic form of conditional checking and flow control.

YASS
if($a < 10)
  //Do something
elseif ($b > $a && $b < 15)
  //Do something else if something
else
  //Do something else
end if

//Alternatively, as of version 1.3.4.90, if statements can be a single line, terminated with a semi-colon
if ($m == 10) print("It does indeed");
  

Version 1.6.6 added an additional syntax for the if statement that uses the then keyword, officially known as if...then statements:

YASS
if $a < 10 then
  //Do something

if $a < 10 then print("It does indeed")
  

The then statement is different from a standard if statement in that it can only have a single action inside the statement and does not end with either a brace or end if:

YASS
if $a < 10 then
  print("Hello 1")
print("Hello 2")
  

The "Hello 2" string is not in the if statement however, the "Hello 1" is.

Prior to version 1.7.11, the then keyword was simply syntactic sugar and did not construct a action line if statement.

Else statements can also be added to if...then statements:

YASS
if $a < 10 then
  print("Hello 1")
else
  print("Hello 2")
  

It should noted that these else statements must be a single expression like the if...then statement.

Version 1.6.7 also added the new else if to compliment the original elseif - either is valid:

YASS
if ($a < 10)
  //Do something
elseif ($b > $a && $b < 15)
  //Do something else if something
else if ($c > $a && $c < 15)
  //Do something else if something
else
  //Do something else
end if
  
Comments

There are no comments on this page.

New comment
Reply
Provide feedback on this page
Comments are sent via email to me.