Loop "For" Version 11 (Java)
Action group: Base actions
Description
This action is intended to provide the specified iteration on the step counter.
To add a sequence of actions to the loop body, you must move them to the "Loop For" action loop.
Action icon
Settings of parameters
Property | Description | Type | Filling example | Mandatory field |
---|---|---|---|---|
Parameters | ||||
From | Initial counter value | Robin.Numeric | Yes | |
To | Checked before each iteration of the loop | Robin.Numeric | Yes | |
Increment | Increasing the loop step | Robin.Numeric | Yes | |
Results | ||||
Iteration actual state | Counter value for use in the current loop iteration | Robin.Numeric |
Special conditions of use
Procedure for working with the "For" loop action
1. Select the "For" action from the "Base Actions" action group and transfer it to the script;
2. Fill the body of the loop with the required actions.
Filling example:
3. Set the action parameters:
- From (the value from which the countdown will start).
- To (the value up to which the countdown will continue).
- Increment (the number by which the iterator value will be incremented).
Example of filling:
4. The result of the loop: the state of the iterator, i.e. the counter value to be used in the current iteration of the loop.
Comparison of the "For" and "Foreach" loops.
The "For" loop will do the job the specified number of times. The iterator will take values from the initial specified value to the final value in increments specified in the "Increment" field.
The "Foreach" loop works sequentially with the elements of the selected collection. The number of iterations is equal to the number of elements in the collection selected on the input.
Thus, the result of the "For" loop is a number, and "Foreach" is an object.
Example of use
Task
The loop must be terminated if the iterator state is equal to the value "2".
Solution
Add a "For" loop.
Add an "Equal to" action inside the "For" loop.
Add "If" condition inside the "For" loop. Add the "Message in log" action to the "False" branch. Add the "Message in log" action and the "Break the loop" action to the "True" branch.
Implementation
Open the "Base actions" action group.
Place the "For" loop action in the Studio workspace and set its parameters.
"From" parameter. Set the initial value of the counter for the loop.
"To" parameter. Set the final counter value for the loop.
"Increment" parameter. Set the value by which the counter will be incremented.
Place the "Equal to" action inside the "For" loop in the Studio workspace. This action will check if the current value of the loop counter is equal to the specified value.
In the "First operand" parameter we specify the current state of the loop iterator (counter).
In the "Second operand" parameter we specify the value "2".
Place the "If" action inside the "For" loop in the Studio workspace (see the description of the "If" action).
Set the condition. The condition will be the result of the "Equal to" action.
Place the "Message in log" action in the "If" action workspace of the "False" branch (see the description of the "Message in log" action).
Place the "Message in log" action in the "If" action workspace of the "True" branch (see the description of the "Message in log" action).
Place the "Break the loop" action in the "If" action workspace of the "True" branch (see the description of the action "Break the loop (Base actions)").
Launch the robot using the "Start" button in the top panel. The final scheme of the robot will look as follows:
Result
The robot completed successfully. The algorithm went through the loop and was interrupted after setting the iterator state to "2".
Case " String numbering". Loop "For".
Task
Number the first 10 rows in column "A" in an Excel file.
Solution
Move the "Open" loop action to the studio workspace.
Move the "For" loop action into the Studio workspace.
Move the "Set cell value" action inside the "For" loop to the Studio workspace.
Move the "Save" action to the Studio workspace.
Move the "Close" action to the Studio workspace.
Implementation
Move the "Open" loop action to the studio workspace.
"Path to file" parameter. Specify the path to the Excel file to be opened.
Move the "For" loop action to the Studio workspace and set its parameters.
"From" parameter. Set the initial value of the counter for the loop.
"To" parameter. Specify the final counter value for the loop.
"Increment" parameter. Set the value by which the counter will be incremented.
Move the "Set cell value" action to the Studio workspace inside the "For" loop.
"Context" parameter. Specify the context of the opened Excel file.
"Column of the cell" parameter. Specify the name of the column in which row numbering will be performed.
"Row of the cell" parameter. Specify the number of the row in which the value will be filled. In this case, the value of the loop counter is specified.
"Value" parameter. Specify the value that will be written to the cell. In this case, the value of the loop counter is specified.
Move the "Save" action to the studio workspace.
"Context" parameter. Specify the context of the opened Excel file.
Move the "Close" action to the studio workspace.
"Context" parameter. Specify the context of the opened Excel file.
Launch the robot using the "Start" button in the top panel.
Result
The robot completed successfully.
The algorithm looped through, the rows in the selected column of the excel file were numbered.