SWITCH - multi-choice branch



<SWITCH switchValue>
  <CASE value1[ /]>
    ... statements if switchValue = value1 ...
  <CASE op value2[ /]>
    ... statements if switchValue op value2 is true ...
  <DEFAULT[ /]>
    ... statements if no <CASE> matches ...

The SWITCH statement provides a multi-option branch based on a given switchValue, which is a single variable or literal. The value of switchValue is compared against each CASE value, in the order they appear in the script, until one matches. The statements that follow the matching CASE are executed, up to the closing </CASE>, or next <CASE>, <DEFAULT>, or closing </SWITCH> tag. Only the first matching CASE (if any) is executed. If none of the CASEs match, then the statements after the <DEFAULT> tag, if present, are executed.

An optional operator can be given in a CASE to use in comparing its value to the SWITCH value, instead of the default eq. This can be useful in checking a range of values; note the order of CASE statements here:


<SWITCH $temp>
  <CASE lte 32> Ice
  <CASE lt 60>  Cold water
  <CASE lt 100> Warm water
  <CASE lt 212> Hot water
  <DEFAULT>     Steam

The same operators that are translated in <IF> (here) are supported in <CASE>.

Similar to IF. Note that </CASE> is not needed; execution doesn't fall through to the next CASE as in C. The DEFAULT clause, if present, must be last, since CASEs are checked in order of appearance.


Copyright © Thunderstone Software     Last updated: Aug 4 2020
Copyright © 2021 Thunderstone Software LLC. All rights reserved.