A loop is a sequence of instructions that is continually repeated until a certain condition is reached. Typically, a particular process is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number. If it hasn't, the next instruction in the sequence is an instruction to return to the first instruction in the sequence and repeat the sequence. If the condition has been reached, the next instruction "falls through" to the next sequential instruction or branches outside the loop. A typical case would be to go through a number of lines from an Excel spreadsheet, a data table or a web browser table to perform some task for each record.
Loops are one of the most essential and important features available in Foxtrot. It allows the whole or parts of a script to repeat itself for either:
- An exact number of times
- When the "Exact times" option is selected, an additional option will appear, allowing you to control how many times the loop will repeat before stopping.
- The "Forever" option does not have any additional settings. A loop that is configured to run Forever will only stop when instructed to do so with the use of an Exit Loop Action.
- According to a Files & Folders List
- When the "Files & Folders List" option is selected, you will be prompted to select the desired List. You may also specify the Start and Stop boundaries of the Loop. To use the Files & Folders List option, your Project must first contain a Files & Folders List. A Files & Folders List can only be created using the Create List Action.
To create a loop, select Loops Actions to expand the Action list. Select the Loop Action from the Actions list to display the Action Builder.
In the attached file (find at the end of the article), you can get an example of how to make a loop in a web browser. You can download the script and try to run it. Remember to save the Foxtrot Project File to the same location as your other projects, typically in this destination: C:\ProgramData\Foxtrot Suite
This example shows how to build a loop that involves Excel file and a web browser. The key to making successful loops is determining the number of times to perform the loop - or turned around - when to exit the loop.
- In this example, Foxtrot starts by setting up a Workbook in Excel, making some columns and formatting the first row:
- Then Foxtrot goes to the website and makes navigation:
- Now, Foxtrot performs a loop - running through the table on the website, copy the values and paste them into the Excel table. This loop is executed forever - until the last row in the web table is reached:
- When the loop is finished, Foxtrot clears the variable and saves the Workbook:
- The result looks like this: