专业中山建网站公司,做网站的名字大全,网站建设资格预审公告,南昌网站推广公司ANSYS Swan 表达式支持选择(selection)表达式 case, if/then/else。选择表达式根据特定的条件选择不同的分支流。
if/then/else 表达式
if/then/else 表达式的文法如下
if expr then expr else expr 其中#xff0c;首个expr 的布尔表达式#xff0c;若其为 true, 则返回 …ANSYS Swan 表达式支持选择(selection)表达式 case, if/then/else。选择表达式根据特定的条件选择不同的分支流。
if/then/else 表达式
if/then/else 表达式的文法如下
if expr then expr else expr 其中首个expr 的布尔表达式若其为 true, 则返回 then 分支的流若为false则返回 else 分支的流。
如下示例为 if/then/else 的使用
function ifThenElseExpr (i: bool)
returns (o: int32)
{
let o if i then 24 else 42;
}case 表达式
case 表达式按匹配值选择相应的流。其文法如下
(case expr of (| pattern: expr ))文法中首个 expr 的类型可以是布尔表达式。比如下面的例子:
function caseExpr (i1: bool)
returns (o: int32)
{let o (case i1 of | true : 24| false :42);
}case 后的 expr 也可以是枚举类型。比如下面的例子:
type E1 enum {LEFT, RIGHT};function caseExpr2 (i: E1)
returns (o: int32)
{
let o (case i of | LEFT:24| RIGHT:42);
}case 后的expr 可以是整数或字符类型。如果是此类情况需要额外包含default 匹配模式。比如下面的两个例子:
function caseExpr3 (i: int32)
returns (o: int32)
{
let o (case i of | 1 : i1 | 2 : i2 | 3 : i3 | default : i);
}function caseExpr4 (i: char)
returns (o: int32)
{
let o (case i of | a : 24 | default : 42);
}