Repeats a block of commands while a condition is true.

Command availability: IBM RPA SaaS and IBM RPA on premises


Terminate the command block with the End While (endWhile) command.

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

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

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Left operand left Required Any Value used to evaluate the condition.

If the defined variable is of type Number, the default value is 0.
Operator operator Required ConditionalOperators Rule used to evaluate the condition. For more information, see operator parameter options.
Right operand right Required when Operator is Equal_To, Greater_Than, Greater_Than_Equal_To, Less_Than, Less_Than_Equal_To, Contains, Ends_With, Begins_With, Matches Any Value that is compared to the Left operand to evaluate the condition.
Negate negate Optional Boolean Negates the rule defined in Operator.

operator parameter options

The following values are supported for the Operator expression that evaluates the condition.

  • Begins with
  • Contains
  • Ends with
  • Equal to
  • Greater than
  • Greater than or equal to
  • Is empty
  • Is null
  • Is null or empty
  • Is true
  • Less than
  • Less than or equal to
  • Matches


Example 1: Increments the value of the incrementVar by one, and stops until the value is no longer less than 5.

defVar --name verifyValue --type Numeric
while --left "${verifyValue}" --operator "Less_Than" --right 5
    incrementVar --number ${verifyValue}
    logMessage --message "${verifyValue}" --type "Info"
// Result of operation:
// 1
// 2 
// 3
// 4
// 5

Example 2: In a similar situation, the variable verifiedValue starts with a value of 8, and the loop decrements it until the value is no longer greater than 5.

// The value to be verified is equal to 8.
defVar --name verifiedValue --type Numeric --value 8
while --left "${verifiedValue}" --operator "Less_Than" --right 5 --negate
    logMessage --message "${verifiedValue}" --type "Info"
    decrementVar --number ${verifiedValue}
// Result of the operation:
// 8
// 7
// 6
// 5