"While (Pre-condition Loop)" Activity

Created by akaBot Support, Modified on Mon, 18 Nov, 2024 at 4:44 PM by akaBot Support


TABLE OF CONTENTS


1. Activity Program Name

System.Activities.Statements.While


2. Description

  • Studio Version ~2.0.2.0:
    Quick Access: Toolbox > Control Flow > While (Pre-condition Loop)

  • Studio Version from 2.0.3.0:
    Quick Access: Toolbox > System > Control Flow > While (Pre-condition Loop)

This activity repeatedly executes a specified process as long as a condition is met. The condition is checked before the process is executed. If the condition is not satisfied, the process may not be executed even once.


3. Properties


Property field

Property name

Input type

Description

Others

Public

Checkbox

Variables and arguments within the activity are written to the log file and pushed to the Center. (For details, refer to "Property Item 'Public'").

Condition


Condition Input (Boolean Type)

The repeat process executes as long as the condition evaluates to True.

Display name

Input Value (String Type)

Reflected as the activity name in the Designer Panel.


4. How to use

Let’s create a robot that displays a message box for a specified number of times using the While (Pre-condition) activity.

Step-by-step instructions:

Add Input Dialog: First, set up an input dialog to specify the number of repetitions. Drag and drop the Input Dialog activity from the Toolbox to the designer panel.

Set Output Variable: In the properties panel, set the Output > Result field to store the value entered in the dialog. If no variable has been created, create one using the "Create Variable" function. In this example, the variable name is in_num and the type is Object.

Configure Input Properties: Optional fields, but here are the settings for this example:

  • Label "Please tick the number that you want to be displayed on the Message box"

  • Options{"0","3","7"}

  • Title "While (Pre-condition) Sample"

Next, prepare a variable to count the number of repetitions. Set the initial value to "0". Drag and drop the "Assign" activity from "Original > Assign" into the design panel.

In the activity, specify the variable name to store the "number of repetitions" on the left side ("To"). (You can also set this from the properties panel under "Others > To"). If the variable has not been created yet, create the variable and specify it. The variable type should be "Int32".

Enter "0" on the right side ("Value") in the activity. (You can also set this from the properties panel under "Others > Value").


Starting Message: Add a message box to announce the start of the process. Drag and drop the Core > Message Box activity and set the Text property to "Display a message box that says 'Processing Loop' for " + in_num.ToString + " times."


Drag and drop the "While" activity from "Control Flow > While" in the toolbox to the design panel.

Specify the condition for repetition in the "Condition" field. When the condition is True, the process described in the "Body" will repeatedly execute. In this example, the condition is "The number of repetitions is less than the specified count." The "Body" contains the process you want to repeat, which is "displaying a message box" in this case. Since the "Condition" is placed before the "Body," if the condition is not met, the "Display Message Box" process will not execute at all.


Specify the condition for repetition inside the "Body" In this example, the condition is that the process inside the "Body" will repeat until the number of repetitions is less than the specified count. Set the "Condition" to i < CType(in_num, System.Int32). The CType function converts the object type into another data type. (Refer to "Data Type Conversion" for more details.)


Drag and drop a "Sequence" activity from "Control Flow > Sequence" into the "Body" area in the design panel.


Display a message box. Drag and drop the "Message Box" activity from "Core > Message Box" into the design panel, and set the "Text" property of the activity to  "【Processing Loop】(" + (i+1).ToString + "th time)"

(You can also set this from the "Text" field in the properties panel.)


After displaying the message box, increment the count. Drag and drop the "Assign" activity from "Original > Assign" into the design panel, and set the left side (To) of the activity to the variable used for counting (i), and the right side (Value) to i + 1. (You can also do this from the properties panel.)


Now the "While" activity settings are complete. After exiting the loop, display a completion message. Drag and drop a "Message Box" activity from "Core > Message Box" into the design panel, and set the "Text" property of the activity to in_num.ToString + “times the message box was displayed.” + vbNewLine + “End”

 (You can also set this from the "Text" field in the properties panel.)




Click "Home > Start" or press the "F5 key" to run the process.

Execution Result:

A message box is displayed based on the number of times specified in the input dialog. Below are screenshots showing the results when "3" and "0" were selected.

When selecting "3" in the input dialog:

  • Start Message

  • The portion of the Body that displays the specified number of message boxes

  • End Message


When selecting "0" in the input dialog:

  • Start Message

  • The portion of the Body that displays the specified number of message boxes (no message box displayed)

  • End Message










Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article