Loop Action Icon

Loop

Declaration

<AMLOOP FROM="number" TO="number" STEP="number" RESULTVARIABLE="text">

See Also

Loop | End Loop | Loop Files | Loop Windows | Loop Processes | Loop Expression | Loop Dataset | Loop List | Loop List Control | Loop Processes | Loop Tree Control | Loop Windows | Break

Description

Loops through the range of numbers specified. With each successive loop, a block of steps are executed. An index variable can optionally update the current loop count. The loop ends after the counter has reached the number specified or when a Break is encountered. This action is often distinguished by an explicit loop counter or loop variable allowing the body of the for loop (the steps that are being repeatedly executed) to know about the sequencing of each iteration.

Practical Usage

Frequently used in to loop a series of steps a number of times.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

Total Loops

Number

Yes if From and To parameters are not specified

1

TOTALLOOPS="10"

The number of loops to be performed. If the Starting Index and Ending Index parameters are specified, this parameter is ignored.

NOTE: Specifying TOTALLOOPS="10" is the same as specifying FROM="1" and TO="10"

Starting Index

Number

Yes if Total Loops parameter is not specified

1

FROM="3"

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. If the Total Loops parameter is specified, this parameter is ignored.

Ending Index

Number

Yes if Total Loops  parameter is not specified

1

TO="10"

The number to count up to when determining the number of times to loop. If the Total Loops parameter is specified, this parameter is ignored.

 

Advanced Properties

Property

Type

Required

Default

Markup

Description

Increment by step

Number

No

1

STEP="2"

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

Populate variable with index count

Text

No

1

RESULTVARIABLE="theVar"

The name of the variable to populate with the current counter value. This number starts at the value entered in the Starting Index parameter and is incremented by the value entered in the Increment by step parameter until it reaches the value entered in the Ending Index parameter.

 

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

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

 

Sample Task 1 - Loop action used to loop a total of 5 times. A Message Box is contained inside the Loop/End Loop block to display the sequencing of each iteration.

 

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

<AMLOOP TOTALLOOPS="5" RESULTVARIABLE="theCounter">

     <AMMESSAGEBOX>This is iteration number %theCounter%.</AMMESSAGEBOX>

</AMLOOP>

 

 

Sample Task 2 - Loop action used to loop through a range with the starting index set to 1 and the ending index set to 10. The number by which the index is increased by is set to 3. A Message Box is contained in the body of the loop to display the current index during each iteration.

 

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

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

     <AMMESSAGEBOX>This is index %theCounter%.</AMMESSAGEBOX>

</AMLOOP>

 

 

Sample Task 3 - Loop action used to loop a total of 10 times. A Message Box is contained inside the Loop/End Loop block to display the sequencing of each iteration followed by an If statement to determine if the current iteration is 5. If TRUE, a Break is encountered.

 

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

<AMLOOP TOTALLOOPS="5" RESULTVARIABLE="theCounter">

     <AMMESSAGEBOX>This is iteration number %theCounter%.</AMMESSAGEBOX>

</AMLOOP>

 

↑ Top of Page