Сравнение версий

Ключ

  • Эта строка добавлена.
  • Эта строка удалена.
  • Изменено форматирование.

...

Do while Version 12 (Java)

Группа действий: Базовые действия 

Описание

Данное действие предназначено для создания цикла действий, который выполняется до тех пор, пока результат условия равен "True". Для добавления условия используется инструмент построения выражений в параметре «Условие». Для добавления в тело цикла последовательности действий необходимо переместить их на контур блока "Тело цикла".

Image Removed

...

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.


Image Added

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 "Basic Actions" action group and transfer it to the script1.Выбрать действие"Do While" из группы действий «Базовые действия» и перенести в сценарий.


2.  Заполнить тело цикла необходимыми действиями.
Пример заполненияFill the loop body with the necessary actions.
Filling example:

3.  Заполнить параметры действия "Условие"

Пример заполнения:

Image Removed

Если условие заполняется посредством инструмента построения выражений, то оно отобразиться в разделе «Условие» внутри цикла.

Пример цикла с постусловием, где условие заполнено с помощью инструмента построения выражений:

Image Removed

Сравнение циклов «While» и цикла с «Do While».

Оба цикла работают до тех пор, пока результат условия равен "True". Однако в цикле "While" проверка действия происходит перед началом выполнения цикла, т.е. цикл может отработать 0 раз и более.

Проверка условия в действии"Do While" происходит после выполнения действий в теле цикла, т.е. цикл отработает минимум один раз.

Пример использования

Set the "Condition" action parameters.

Filling example:

Image Added


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:

Image Added

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

Задача

В папке есть несколько подпапок, где лежит необходимый нам файл. Нужно просмотреть подпапки и выяснить в какой из них сохранен этот файл.

Решение

1. Создать переменную «Счетчик», тип переменной – число.

2. Создать переменную «Значение», тип переменной – объект.

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"3. На рабочую область перенести действия "Folder list" (группа действий «Файловая система»),"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" :
  5. В параметр «Папка» указать путь до папки с подпапками.
  6. В параметре «Тип объектов» выбрать из выпадающего списка значение «Только папки».
    Image Removedaction 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.

      Image Added
  7. 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.
    2. В параметр условие с помощью инструмента построение выражений записать условие «Длина коллекции, полученной в результате действия «Найти файл» равно 0». Для этого создадим еще одну переменную «Доп. переменная», в которой будет записано число 0
      Пример:

       



    3. В тело цикла добавить действия 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.


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

    1. "Collection" parameter -

    Заполнить параметры действия «Получить значение по индексу»:

    1. Параметр «Коллекция» - результат действия "Folder list" action result.
    2. Параметр «Индекс» - переменная «Счетчик».
    3. Параметр «Результат» - переменная «Значение».
      Image Removed
    Заполнить параметры действия «Конвертировать данные»:
  9. Параметр «Источник» - результат действия «Получить значение по индексу».
  10. Параметр «Тип» - путь к папке.
    Image Removed
    Заполнить параметры действия «Найти файл»:
  11. Параметр «Путь к папке» - результат действия «Конвертировать данные».
  12. Параметр «Имя файла» - название искомого файла.
    Image Removed
  13. Заполнить параметры действия «Сложение»:
    1. Первое слагаемое – переменная «Счетчик».
    2. Второе слагаемое – 1.
    3. Результат – переменная «Счетчик».
      Image Removed
  14. Запустить робота по кнопке "Запуск" в верхней панели.

Результат

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

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

  3. Set the "Addition" action parameters:
    1. The first addendum - "Counter" variable.
    2. The second addendum - 1.
    3. Result - "Counter" variable.
      Image Added
  4. 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".Алгоритм пройдет по циклу до тех пор, пока не будет найден искомый файл. Путь до папки с этим файлом будет сохранен в переменную «Значение».