//switch expression analog: a function
//with case filling the Result
function DescribeSize(InchSize: Integer): string;
begin
case InchSize of
14, 15: Result := 'too small';
16..18: Result := 'good for the past decade';
19..23: Result := 'for office work';
24..27: Result := 'great choice';
else
Result := 'are you sure this isn''t a TV?';
end;
end;
var
InchSize: Integer;
begin
InchSize := 24;
WriteLn('Monitor ', InchSize, '" is ',
DescribeSize(InchSize));
//printed: great choice
end.
| Swift предоставляет сокращенный оператор switch, который можно использовать при присвоении значений. |