The choose Statement


The choose statement has the following form.

choose expression
{
 constant_a
  statement

 constant_b
  statement
 ...
 default
  statement
}

The choose expression must be of string type. No two cases can have the same value. The default case is executed when no case constants match the choose expression. The default case is optional and if not present, no action is taken when all matches fail. When a match is made, the coresponding statement is executed.

A choose statement is stored as a dictionary of instructions keyed off the strings. Thus it is feasible to have hundreds of cases without affecting performance.

The following example prints out hello.

generic sampleF
{
  sampleF() // choose is a binary switch - you can have hundreds of cases
  {
      choose "hello"
      {
          "hello"
          {
              s = "hello"
              s.println()
          }
          "world"
          {
              s = "world"
              s.println()
          }
      }
  }
}