Loop - Expression

Declaration

<AMLOOP ACTIVITY="expression" CONDITION="until" EXPRESSION="text">

Description:

Loops while or until the specified expression is true. With each successive iteration, the expression is re-evaluated. The loop ends after the condition is met or when a Break is encountered.

Practical Usage

Used to continue executing a block of steps while or until a condition is met.

Parameters

General

Property

Type

Required

Default

Markup

Description

Condition

Text (options)

Yes

While

  1. CONDITION="while"

  2. CONDITION="until"

Specifies whether the loop should continue while the expression is true or until it is true. The available options are:

  • Loop while the expression is true (default) - Example: Execute the code while x equals five.

  • Loop until the expression is true - Example: Execute the code until x equals five.

Expression

Text

Yes

(Empty)

EXPRESSION="thenumber=55"

A valid BASIC expression that should be evaluated on each loop.

Description

Error Causes

On Error

Example

NOTE: The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.

Sample 1: Loop until expression is true. This task will loop until the expression MyCounter=5 evaluates to TRUE. Within the loop, a dialog box will appear showing the current value of the variable which increments by one upon each successive loop.

 

<AMVARIABLE NAME="mycounter">1</AMVARIABLE>

<AMLOOP TYPE="EXPRESSION" EXPRESSION="mycounter=5" CONDITION="until">

     <AMMESSAGEBOX>%mycounter%</AMMESSAGEBOX>

     <AMINCREMENTVARIABLE RESULTVARIABLE="mycounter" />

</AMLOOP>

 

 

Sample 2: Loop while the expression is true. This task will loop until the 'MyCounter' variable does not equal to 1 or 2. Within the loop, a dialog box will appear showing the current value of the variable.

 

<AMVARIABLE NAME="mycounter">1</AMVARIABLE>

<AMLOOP TYPE="EXPRESSION" EXPRESSION="mycounter=1 or mycounter=2">

     <AMMESSAGEBOX>%mycounter%</AMMESSAGEBOX>

     <AMINCREMENTVARIABLE RESULTVARIABLE="mycounter" />

</AMLOOP>