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 group

Action parameters

Input parameters

  1. "From" field. The initial value of the counter.
  2. "To" field. The final value of the counter.
  3. "Increment" field. Increase of the loop step.

Output parameters

  1. "Iteration actual state" field. Counter value, to be used in the current loop iteration.

Settings

PropertyDescriptionTypeFilling exampleMandatory field
Parameters
FromInitial counter valueRobin.Numeric
Yes
ToChecked before each iteration of the loopRobin.Numeric
Yes
IncrementIncreasing the loop stepRobin.Numeric
Yes
Results
Iteration actual stateCounter value for use in the current loop iterationRobin.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:

    1. From (the value from which the countdown will start).
    2. To (the value up to which the countdown will continue).
    3. 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

  1. Add a "For" loop.

  2. Add an "Equal to" action inside the "For" loop.

  3. 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

  1. Open the "Base actions" action group.

  2. Place the "For" loop action in the Studio workspace and set its parameters.

    1. "From" parameter. Set the initial value of the counter for the loop.

    2. "To" parameter. Set the final counter value for the loop.

    3. "Increment" parameter. Set the value by which the counter will be incremented.



  3. 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.

    1. In the "First operand" parameter we specify the current state of the loop iterator (counter).

    2. In the "Second operand" parameter we specify the value "2".



  4. Place the "If" action inside the "For" loop in the Studio workspace (see the description of the "If" action). 

    1. Set the condition. The condition will be the result of the "Equal to" action.



  5. Place the "Message in log" action in the "If" action workspace of the "False" branch (see the description of the "Message in log" action).

     

  6. Place the "Message in log" action in the "If" action workspace of the "True" branch (see the description of the "Message in log" action).


  7. 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").

  8. 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

  1. Move the "Open" loop action to the studio workspace.

  2. Move the "For" loop action into the Studio workspace.

  3. Move the "Set cell value" action inside the "For" loop to the Studio workspace.

  4. Move the "Save" action to the Studio workspace.

  5. Move the "Close" action to the Studio workspace.

Implementation

  1. Move the "Open" loop action to the studio workspace.

    1. "Path to file" parameter. Specify the path to the Excel file to be opened.



  2. Move the "For" loop action to the Studio workspace and set its parameters.

    1. "From" parameter. Set the initial value of the counter for the loop.

    2. "To" parameter. Specify the final counter value for the loop.

    3. "Increment" parameter. Set the value by which the counter will be incremented.



  3. Move the "Set cell value" action to the Studio workspace inside the "For" loop.

    1. "Context" parameter. Specify the context of the opened Excel file.

    2. "Column of the cell" parameter. Specify the name of the column in which row numbering will be performed.

    3. "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.

    4. "Value" parameter. Specify the value that will be written to the cell. In this case, the value of the loop counter is specified.

  4. Move the "Save" action to the studio workspace.

    1. "Context" parameter. Specify the context of the opened Excel file.



  5. Move the "Close" action to the studio workspace.

    1. "Context" parameter. Specify the context of the opened Excel file.



  6. 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.

  • Нет меток