//switch 表达式的对应物:
//带 case 的函数,由它填充 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 provides a shorthand spelling of switch that you can use when setting values. |