Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

ArgumentTypeDescription
conditionNBooleanThe condition to be checked. If it evaluates to true the corresponding result is returned and the switch statements ends.
resultNStringResult to be returned if the condition is True.
defaultResultStringIf no previous condition has evaluated to True, this is the result to be returned.

Examples

Simple

This example shows how attribute in.city, can be used to set a region value. If none of the codes are matched, "Unknown" is the default value returned.

Code Block
switch( 
   
   [in.city == "Cambridge", "South"], 
   [in.city == "Manchester", "North"],
   "Unknown" 
)

Returns "South" if in.city = "Cambridge".

Combined

This example shows how attribute in.cli, holding a telephone number, can be compared to a number of start codes and resolved to a destination. If none of the codes are matched, "Elsewhere" is the default destination returned.

...

Returns "Cambridge" if in.cli = "01223456765".


Output to a variable

This example shows how attribute in.city, can be used to set an output variable with a region value. If none of the codes are matched, the output variable is set to "Unknown" is the default value returned.

Code Block
switch( 
   
   [in.city == "Cambridge",  $output = "South"], 
   [in.city == "Manchester", $output = "North"],
   $output = "Unknown" 
)

Returns "South" the value set in the output variable. For example if in.city = "Cambridge", $output would be set to "South". This is a useful technique when combining a switch statement with other functions.

See Also