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/YASS documentationWhen-Is statements

When-Is statements are similar to the switch/case statements found in other languages like Java or Visual Basic. The do keyword is entirely optional as well.

YASS
when($a)
  is 0 do
    //Do something when $a = 0
  is 1 do
    //Do something when $a = 1
  is 2 do
    //Do something when $a = 2
  otherwise do
    //Do something when $a is something else
end when
  

The When-Is statement can also be written with braces like PHP or C:

YASS
switch($a) {
  case 0
    //Do something when $a = 0
  case 1
    //Do something when $a = 1
  case 2
    //Do something when $a = 2
  default
    //Do something when $a is something else
}
  

Efficiency of the When-Is statement

ZPE 1.7.12 (December 2019) changed the way that the When-Is statement works so that instead of generating an FAST for the cases, it generates a hash-map using a strong-key hashing mechanism. Unfortunately, this means that with smaller statements the efficiency is actually worse. However, with larger statements it is considerably better due to instant access.

Comments
Code previewClose
Feedback 👍
Comments are sent via email to me.