CASE

CASE(expression, caseval => value, [... , caseval => value ] [, elsevalue ] )

expressionAn expression that results in a single value.
casevalA value to compare against the result of the expression.
=>The "results in" operator--valid only in CASE, MAP and CHOOSESETS.
valueThe value to return. This may be any expression or action.
elsevalueOptional. The value to return when the result of the expression does not match any of the caseval values. May be omitted if all return values are actions (the default would then be no action), or all return values are record sets (the default would then be an empty record set).
Return:CASE returns a single value, a set of values, a record set, or an action.

The CASE function evaluates the expression and returns the value whose caseval matches the expression result. If none match, it returns the elsevalue.

There may be as many caseval => value parameters as necessary to specify all the expected values of the expression (there must be at least one). All return value parameters must be of the same type.

Example:

//simple example
MyExp := 1+2; 
MyChoice := CASE(MyExp, 1 => 9, 2 => 8, 3 => 7, 4 => 6, 5);
  // returns a value of 7 for the value of MyExp=3
OUTPUT(MyChoice);

//example using a DATASET
personRecord := RECORD
  STRING UID;
  STRING first_name;
  STRING last_name;
  STRING address;
  STRING city;
  STRING state;
  STRING zip;
END;
person := DATASET([{'923','James','Jones','123 Elm Street','Hollywood','FL','33022'},
                   {'924','Sally','Jones','22 Main Street','Tampa','FL','33604'},
                   {'925','Jose','Gomez','111 Biscaya Lane','Miami','FL','33101'},
                   {'926','Adam','Wesson','77 Sunset Blvd','Boston','MA','02108'},
                   {'927','Evelyn','Murray','740 SW 10th Street','Boston ','MA','02116'},
                   {'928','Joe','Yung','7511 Simson Avenue','Chicago','IL','60131'}], personRecord);

MyRecSet := CASE(MyExp, 1 => Person(state = 'FL'),
    2 => Person(state = 'GA'),
    3 => Person(state = 'MA'),
    4 => Person(state = 'IL'),
    person);
  // returns set of MA Persons for the value of MyExp=3
  // set MyExp to a number > 4 to get all records
OUTPUT(MyRecSet);

See Also: MAP, CHOOSE, IF, REJECTED, WHICH