Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationWhen-Is statements

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
Feedback 👍
Comments are sent via email to me.