For
Starts a repetition structure, while changing the value of a control variable.
Command availability: IBM RPA SaaS and IBM RPA on premises
Dependencies
You must terminate the block with the Next (next
) 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.
for --variable(Numeric) --from(Numeric) --to(Numeric) --step(Numeric)
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 |
---|---|---|---|---|
Variable | variable |
Required |
Number |
Variable to control the amount of repetitions. When its value reaches the value of To, the repetitions stop. |
From | from |
Required |
Number |
Starting value that the Variable receives to start the iterations. |
To | to |
Required |
Number |
Value that terminates the repetition structure.. |
Step | step |
Required |
Number |
Value used to change the value of the Variable after each iteration. |
Example
The For command repeats the execution of the command block until the value of the variable iterator
reaches 5.
defVar --name iterator --type Numeric
for --variable ${iterator} --from 1 --to 5 --step 1
logMessage --message "Repetition number: ${iterator}" --type "Info"
next
logMessage --message "End for" --type "Info"
// Repeats the command block 5 times.