Loop Action

Declaration

<AMLOOP TOTALLOOPS="number" FROM="number" TO="number" INDEX="text" STEP="number">
  (block of steps to loop)

See Also

End Loop, Loop Files, Loop Windows, Loop Processes, Loop Expression, Loop Dataset, Loop List, Break

Description

Loops through a range of numbers. The variable specified in the Index parameter is updated with the current loop count. With each successive loop a block of steps are executed and the loop counter is incremented by the number specified in the Step parameter. The loop ends after the counter has reached the number specified in the stop parameter or when a Break is encountered.

Practical Usage

Commonly used to loop a block of steps through a range of numbers or loop a certain number of times.

Parameters

General Tab

Total Loops

Number, Required (if FROM and TO are not specified)
MARKUP: TOTALLOOPS="10"

Specifies the number of loops to be performed. Specifying TOTALLOOPS=5 is the same as specifying FROM=1 and TO=5

From

Number, Required (if TOTALLOOPS is not specified)
MARKUP: FROM="10"

Specifies the number to start counting from when determining the number of times to loop. This value will be reflected in the index value returned as well.

To

Number, Required (if TOTALLOOPS is not specified)
MARKUP: TO="20"

Specifies the number to count up to when determining the number of times to loop.

Advanced Tab

Step

Number, Optional - Default 1
MARKUP: STEP="2"

The number by which the index is incremented by when looping through the FROM= and TO= parameters. For example, if FROM=1 and TO=10 and STEP=2 then the action would loop 5 times, if STEP=1 then it would loop 10 times.

Index

Text, Optional
MARKUP: INDEX="VARNAME"

Species the name of a variable to populate with the current counter value. This number starts at FROM= and is incremented by STEP= each loop, until TO= is reached.

Notes

Custom Description

This action includes the Description tab for entering a custom step description.

More on setting custom step description

Standard Error Handling Options

This action also includes the standard Error Causes and On Error failure handling options/tabs.

More on Error Handling Options

Variables and Expressions

All text fields allow the use of expressions, which can be entered by surrounding the expression in percentage signs (example: %MYVARIABLE%, %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by pressing F2.

More on variables
More on expressions

More on the expression builder

Examples

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

 

This task simply creates ten separate folders in a particular directory, sequentially numbering each folder from 1 to 10.


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

<AMLOOP FROM="1" TO="10" RESULTVARIABLE="theCounter">

     <AMCREATEFOLDER FOLDER="C:\Temp\Folder%theCounter%" />

</AMLOOP>