If

如果满足定义的条件,那么运行命令块。

命令可用性: 本地 IBM RPA SaaS 和 IBM RPA

依赖关系

使用 End If (endIf) 命令终止命令块。

脚本语法

IBM RPA 的专有脚本语言的语法与其他编程语言类似。 该脚本语法在脚本文件中定义命令的语法。 您可以在 IBM RPA Studio的 脚本 方式下使用此语法。

if --left(Variant) --operator(ConditionalOperators) --right(Variant) [--negate(Boolean)]

输入参数

下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 IBM RPA Studio的脚本方式及其 Designer 方式等效标签中工作时的参数名称。

设计器方式标签 脚本方式名称 必需的 接受的变量类型 描述
左操作数 left Required Any 用于评估条件的值。
运算符 operator Required ConditionalOperators 用于评估条件的规则。 有关更多信息,请参阅 operator 参数选项
右操作数 right OperatorEqual_To, Greater_Than, Greater_Than_Equal_To, Less_Than, Less_Than_Equal_To, Contains, Ends_With, Begins_With, Matches 时必需 Any 左操作数 比较以评估条件的值。
求反 negate Optional Boolean 运算符中定义的规则求反。

operator 参数选项

对条件求值的 Operator 表达式支持以下值。

  • 开头为
  • 包含
  • 结尾为
  • 等于
  • 大于
  • 大于等于
  • 为空
  • 为 null
  • 为 Null 或为空
  • 为 true
  • 小于
  • 小于或等于
  • 匹配

示例

示例 1:在数字变量中存储学生的平均值。 仅当平均值大于 7 时,学生才能参与抽签。

defVar --name studentAverage --type Numeric --value 8
if --left "${studentAverage}" --operator "Greater_Than" --right 7
    messageBox --title Grade --text "Congratulations! You can participate in the draw!" --icon "Information" --buttons "OK" --defaultbutton "FirstButton"
endIf
logMessage --message "${studentAverage}" --type "Info"
// Checks student average and reports you can participate in the draw, as the value is greater than 7.

示例 2:与上一个示例类似,但现在使用了求反参数。 在本例中,不会显示有关抽奖的消息。

defVar --name studentAverage --type Numeric --value 8 
if --left "${studentAverage}" --operator "Greater_Than" --right 7 --negate
    messageBox --title Grade --text "Congratulations! You can participate in the draw!" --icon "Information" --buttons "OK" --defaultbutton "FirstButton"
endIf
logMessage --message "${studentAverage}" --type "Info"
// Checks value of studentAverage, but does not show message since value is greater than 7.