switch. Choosing one of multiple branches

^switch[string to compare]{
   ^case[case1]{action for 1}
   ^case[case2]{action for 2}
   ^case[case3;case4]{action for 3 or 4}
         
   ^case[DEFAULT]{default action}
}

^switch(mathematical expression){
   ^case(case1){action for 1}
   ^case(case2){action for 2}
   ^case(case3;case4){action for 3 or 4}
         
   ^case[DEFAULT]{default action}
}

Operator
switch compares string or result of mathematical expression with values provided in case list. If compared values match it implements matching option's code. If values don't match, it implements code provided by option DEFAULT (must be always in uppercase).

If option
DEFAULT is not provided and none of the case-options matches the value, no code will be implemented.

Example
^switch[$color]{
   ^case[red]{Stop and think of Eternity...}
   ^case[yellow]{
You'd better get ready!}
   ^case[green]{
Show them who's the Highway King!}
   ^case[DEFAULT]{
You'd better not drive if you're color-blind...}
}


Copyright © 1997–2017 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 01.04.2004