Loop - Range

Declaration

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

Related Topics   

Description

Loops through the numerical range specified. With each successive loop, a block of steps are executed. An index variable can optionally update the current cycle count. The loop ends after the counter has reached the number specified or when a Break is encountered.

Practical usage

Frequently used to loop a series of steps a number of times. This activity 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.

Parameters

General

 
PropertyTypeRequiredDefaultMarkupDescription
Start indexNumberYes1FROM="3"The number to start counting from when the loop process begins.
End indexNumberYes1TO="10"The number to count up to when determining the number of times to loop.
At each iteration, increment index byNumberNo1STEP="2"If enabled, specifies the number by which the index is incremented by when looping through the Start index and End index parameters. For example, if Start index=1, End index=10 and At each iteration, increment index by=2, then this activity would loop 5 times.  if At each iteration, increment index by=5, then it would loop 10 times.
Store current index in variableTextNo(Empty)RESULTVARIABLE="theVar"If enabled, specifies the name of an existing 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 At each iteration, increment index by parameter until it reaches the value entered in the End index parameter.

Description

Error Causes

On Error

Examples

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Example 1

A 'Loop Range' activity set to loop a total of 5 times. A Message Box step is placed inside the Loop/End Loop block. During runtime, the message box displays the sequencing of each iteration.

Copy
<AMVARIABLE NAME="theCounter" VALUE="" />
<AMLOOP FROM="1" TO="5" RESULTVARIABLE="theCounter" />
<AMSHOWDIALOG>This is iteration number %theCounter%.</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />

Example 2

A 'Loop Range' activity 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 dialog' activity is contained in the body of the loop. During runtime, it displays the current index during each iteration.

Copy
<AMVARIABLE NAME="theCounter" VALUE="" />
<AMLOOP FROM="1" TO="10" STEP="3" RESULTVARIABLE="theCounter" />
<AMSHOWDIALOG>This is index %theCounter%.</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />

Example 3

Nested loop demonstration. Additional information will be displayed during runtime. 

Copy
<!-- Show message box telling the user what is going on -->
<AMSHOWDIALOG WINDOWTITLE="Sample Task" BUTTONS="ok_cancel" ONSECONDBUTTONCLICK="stop" ICON="information">This sample task demonstrates the following: 1) Use of Nested Loops 2) Use of Variables There are 2 loops, one is embedded inside the other. Each loop will execute 3 cycles.  For each cycle the parent executes, the child (nested loop) will cycle 3 times. Remember, you can always stop a task in progress by pressing CTRL-ALT-END. Press OK to continue running this task or Cancel to stop now.</AMSHOWDIALOG>
<!-- Create counter variables -->
<AMVARIABLE NAME="counter1" VALUE="" />
<AMVARIABLE NAME="counter2" VALUE="" />
<!-- Begin parent loop -->
<AMLOOP FROM="1" TO="3" RESULTVARIABLE="counter1"><!-- Begin nested loop  --><AMLOOP FROM="1" TO="3" RESULTVARIABLE="counter2"><!-- Display results in message dialog  --><AMSHOWDIALOG WINDOWTITLE="Loop Progress" BUTTONS="ok_cancel" ONSECONDBUTTONCLICK="stop">Parent loop is currently executing cycle %counter1% of 3.Nested loop is currently executing cycle %counter2% of 3.</AMSHOWDIALOG><!-- End nested loop  --></AMLOOP><!-- End parent loop  --></AMLOOP>
<!-- Begin nested loop  -->
<AMLOOP FROM="1" TO="3" RESULTVARIABLE="counter2" />
<!-- Display results in message dialog  -->
<AMSHOWDIALOG WINDOWTITLE="Loop Progress" BUTTONS="ok_cancel" ONSECONDBUTTONCLICK="stop">Parent loop is currently executing cycle %counter1% of 3.Nested loop is currently executing cycle %counter2% of 3.</AMSHOWDIALOG>
<!-- End nested loop  -->
<AMLOOP ACTIVITY="end" />
<!-- End parent loop  -->
<AMLOOP ACTIVITY="end" />