Robin contains three kind of loops that can be used to repeat part of an automation.
The first kind of loop is a simple loop with which you can run part of an automation for a certain number of times. The syntax for this loop is as follows.
loop i from 1 to 10 step 1 # Steps within loop end
This loop will repeat 10 times. The variable i is used to increment up to 10. Step 1 denotes that variable i will be increased by 1 every time. As all blocks, the loop requires an end in the end of the block.
The variable and step in a simple loop are optional. The Loop can be set in a format counting from 1 to 10. The default step is 1.
The For each loop, iterates through a list.
In the example below, the list includes numbers from 1 to 5. Hence this loop will repeat five iterations.
loop foreach value in [1,2,3,4,5] # Steps within loop end
The while loop, will repeat the actions nested in the loop, as long as the conditions set in the loop meet.
In this example, the variable i is checked to be true. As long as it’s true it will keep iterating.
loop while i = true # Steps within loop end
Note, that any action which provides a boolean variable result can be used within a While loop using parenthesis ().
In the example below, the file exists action is used.
loop while (File.Exists File: "C:\file.txt") # Steps to perform while file.txt exists end
The list below includes the actions that may be used withtin a loop block.
There is an option to exit a loop during one iteration. This is achieved using the “Exit Loop” statement. That way the loop will be terminated.
loop while i = true if Day = 'Saturday' or Day = 'Sunday' then # Steps within loop & Condition else exit loop end end
Alternatively, to just skip the current loop iteration, use the “Next Loop” statement.
loop while i = true if Day = 'Saturday' or Day = 'Sunday' then # Steps within loop & Condition else next loop end end