Do while Version 12 (Java)

Action group: Base actions 


Description

This action creates an action loop that runs as long as the result of the condition is "True". To add a condition, the expression construction tool is used in the "Condition" parameter. To add a sequence of actions to the loop body, you must move them to the outline of the "Loop body" clause.


Action icon

Settings of parameters

PropertyDescriptionTypeFilling exampleMandatory field
Parameters
ConditionConditionRobin.BooleantrueYes

Special conditions of use

Since this boolean expression is evaluated after each loop execution, the "While" loop is executed one or more times.

How to work with the "Do while" action

1.Select the "Do While" action from the "Base actions" action group and transfer it to the script.


2. Fill the loop body with the necessary actions.
Filling example:

3. Set the "Condition" action parameters.

Filling example:


If the condition is filled in using the expression builder tool, it will appear in the "Condition" section inside the loop.

An example of a loop with a postcondition where the condition is filled in using the expression construction tool:

Comparing the "While" and "Do While" loops

Both loops work as long as the result of the condition is "True". However, in the "While" loop, the action is checked before the loop starts executing, i.e. the loop may run 0 times or more.

The condition check in the "Do While" action takes place after the actions in the loop body are executed, i.e. the loop will run at least once.

Example of use

"Search file" case. "Do While".

Task

There are several subfolders in the folder where the file we need is stored. Look through the subfolders and find out in which of them this file is saved.

Solution

1. Create a variable "Counter", variable type - number.

2. Create a variable "Value", variable type - object.

3. Move the "Folder list" (action group "File system"),"Do While" (action group "Base actions") actions to the workspace.

4. Add actions "Get value by index" (action group "Collections"), "Convert data" (action group "Base actions"), "Search file" (action group "File system") and "Addition" (action group "Operators") to the loop body.

Implementation

  1. Create a variable "Counter", variable type - number.
  2. Create a variable "Value", variable type - object.



  3. Move the "Folder list" (action group "File system"),"Do While" (action group "Base actions") actions to the workspace.

  4. Set the "Folder list" action parameters:
    1. In the "Folder" parameter specify the path to the folder with subfolders.
    2. In the "Objects type" field select "Only folders" value from the dropdown list.

  5. Set the "Do While" action parameters:
    1. Use the expression construction tool to write the condition "The length of the collection obtained as a result of the "Find file" action is 0" into the condition parameter. To do this, create one more variable "Additional variable", in which the number 0 will be written.
      Example:

       



    2. Add actions "Get value by index" (action group "Collections"), "Convert data" (action group "Base actions"), "Search file" (action group "File system") and "Addition" (action group "Operators") to the loop body.


  6. Set the "Get value by index" action parameter:

    1. "Collection" parameter - "Folder list" action result.
    2. "Index" parameter - "Counter" variable.
    3. "Result" parameter - "Value" variable.
  7. Set the "Convert data" action parameter:
    1. "Source" parameter - "Get value by index" action result.
    2. "Data type" parameter - path to file.


  8. Set the "Find file" action parameters:
    1. "Folder path" parameter - "Convert data" action result.
    2. "File name" parameter - name of the needed file.


  9. Set the "Addition" action parameters:
    1. The first addendum - "Counter" variable.
    2. The second addendum - 1.
    3. Result - "Counter" variable.
  10. Click "Start" in the top panel to start the robot.

Result

The algorithm will loop until the desired file is found. The path to the folder with this file will be saved to the variable "Value".


 

  • Нет меток