Loop - Range
Declaration
<AMLOOP FROM="number" TO="number" STEP="number" RESULTVARIABLE="text">
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.
General Parameters
Property |
Type |
Required |
Default |
Markup |
Description |
---|---|---|---|---|---|
Start index |
Number |
Yes |
1 |
FROM="3" |
The number to start counting from when the loop process begins. |
End index |
Number |
Yes |
1 |
TO="10" |
The number to count up to when determining the number of times to loop. |
At each iteration, increment index by |
Number |
No |
1 |
STEP="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 variable |
Text |
No |
(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 tab - A custom description can be provided on the Description tab to convey additional information or share special notes about a task step.
Error Causes tab - Specify how this step should behave upon the occurrence of an error. (Refer to Task Builder > Error Causes Tab for details.)
On Error tab - Specify what AWE should do if this step encounters an error as defined on the Error Causes tab. (Refer to Task Builder > On Error Tab for details.)
Examples
The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.
Sample 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.
<AMVARIABLE NAME="theCounter"></AMVARIABLE> <AMLOOP TOTALLOOPS="5" RESULTVARIABLE="theCounter"> <AMMESSAGEBOX>This is iteration number %theCounter%. </AMMESSAGEBOX> </AMLOOP>
Sample 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.
<AMVARIABLE NAME="theCounter"></AMVARIABLE> <AMLOOP FROM="1" TO="10" STEP="3" RESULTVARIABLE="theCounter"> <AMMESSAGEBOX>This is index %theCounter%.</AMMESSAGEBOX> </AMLOOP>
Sample 3 - Nested loop demonstration. Additional information will be displayed during runtime.
<!-- 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"></AMVARIABLE> <AMVARIABLE NAME="counter2"></AMVARIABLE> <!-- 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>