企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
条件表达式由关键字 if 开始,然后条件表达式放在一个 () 内,如果条件符合,表达式将会执行: > Conditional expressions come in the form of a leading if keyword, a condition expression enclosed in parentheses () and a expression to be evaluated in case the condition holds: ~~~ if (condition) expression; ~~~ 条件表达式必须为Bool类型。 > The condition expression has to be of type Bool. 可选的,表达式可以后跟 else 关键字作为另一个表达式,如果条件不满足,可以执行else后的表达式: > Optionally, expression may be followed by the else keyword as well as another expression to be evaluated if the condition does not hold: ~~~ if (condition) expression1 else expression2; ~~~ 这里 ,expression2 可以认为是另一个 if 表达式: > Here, expression2 may consist of another if expression: ~~~ if (condition1) expression1 else if(condition2) expression2 else expression3 ~~~ 是否一个 if 表达式的值是必须的,例如,对于 var x = if(condition) expression1 else expression2 ,类型工具确保expression1的类型和 expression2 统一(第3.5节)。如果没有 else 表达式被给定,类型被推断为 Void 。 > If the value of an if expression is required,e.g. forvar x = if(condition) expression1 else expression2, the typer ensures that the types of expression1 and expression2 unify (3.5). If no else expression is given, the type is inferred to be Void.