The select Statement


The select statement has the following form.

select variable
{
  enumerator
    statement
  enumerator
     statement
  default
     statement
}

The select expression must be an enumerator. The cases are enumerators from the same enumeration. No two cases can have the same value. The default case is executed when no case constants match the select expression. The default case is optional and if not present, no action is taken when all matches fail. When a match is made, the corresponding statement is executed.

As an example, consider the following program.

enum greek
{
  alpha
  beta
  gamma
}


generic sampleI
{
  sampleI()
  {
     variable = greek.alpha

     select variable // this is a binary operation.
     {
         alpha
         {
             s = "hello"
             s.println()
         }
         beta
         {
             s = "world"
             s.println()
         }
     }
   }
}

Note that the enumerators of the greek enumeration are used without qualification. The variable must be of an enumeration type then the enumerators are specified as shown.

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