Case Expressions

Case expressions make it possible to use case in an expression instead of a standalone statement. Instead of statements, case requires a (single) expression for each element and its else:

method ConsoleApp.ValuesText(aValue: Integer): string;
  exit 'text: ' + case aValue of
      0: 'none';
      1: 'one';
      2: 'two';
      3..5 : 'several';

If the else case is omitted from the case, it defaults to nil (nullable type for value types, else reference type).

The result type of a case expression is the closest type that fits all members. For integers and doubles, it picks the type that can hold all values used (int + double -> double; int + int64 -> int64).