While
Tag: While
The While function creates a a loop without having to use the mechanics of the LOOP action. In short, no lists are needed.
Detailed Description
The While loop is infinite by default. It must be made to stop with a BREAKLOOP action inside the While block, or with a condition directly set at the While level.
While is like a LOOP and an IF combined.
Setting conditions at the While level is similar to the conditions for IF.
While has one more conditional attribute "Max=n" which stops the While after n iterations .
Variables from LOOP like {%LoopIndex%} are available with While.
It is easy to create an infinite loop with While. If it happens, the application freezes (Notes apps) or makes it impossible to run any other automation (job or script, sapio365). The only way to break an infinite While loop is to hit the Cancel Automation button on the console.
Tag Attributes
Attributes | Value Description |
---|---|
Max | Number setting the maximum number of iterations |
Index | Position of current iteration within a loop. Allowed test values:
|
Target | "Tree" "Grid" (for default grid) or Grid name "Var" for variables declared with SetVar "List" |
Test | What the While is about:
|
Mode | How to compare:
|
Value | True / False - Both values only used for FocusRoot and mode for "Exists" lists), or any integer number (SelectionCount, VisibleRowsCount) as well as any text when testing variables |
OnError | Action to take in case of error within While block: "ExitLoop": break loop and continue with script "Next": continue to next loop action item |
This example shows three ways of running a 3-iterations loop:
Example Scripts
<IF target="Grid" test="VisibleRowsCount" mode="LessThan" value="5">
<echo value="VISIBLE IN GRID < 2"/>
</IF>
<ytriaAutomation>
<While max="3">
<Echo value="1. ======> while index: {%loopindex%}"/>
</While>
<While>
<Echo value="2. ======> while index: {%loopindex%}"/>
<if target="var" test="{%loopindex%}" mode="equals" value="3">
<breakLoop/>
</if>
</While>
<While target="var" test="{%loopindex%}" mode="LessOrEquals" value="3">
<Echo value="3. ======> while index: {%loopindex%}"/>
</While>
</ytriaAutomation>
<ytriaAutomation>
<SetVar MyThings="42"/>
<WHILE target="var" test="{%MyThings%}" mode="IsIn" value="312:Georges:42:666">
<MsgBox Message="42"/>
</WHILE>
<WHILE target="var" test="{%MyThings%}" mode="IsNotIn" value="Mugre">
<MsgBox Message="Not Mugre"/>
</WHILE>
</ytriaAutomation>