!LOOP

From iMacros
Jump to: navigation, search
Contains the current loop number when playing a macro in loop/repeat mode. This value is set automatically by iMacros each time the macro repeats as a result of using the Play Loop button (iMacros for Firefox and Chrome) or setting the Repeat value in the sidebar (iMacros browser and iMacros for IE)
Play Loop.png

The !LOOP variable is especially useful together with the POS attribute of the TAG command for iterating over elements on a page, e.g. search result links.

You can also explicitly SET a value for !LOOP at the beginning of the macro to force a different starting value (the default value is 1). For example, you might use SET !LOOP 2 if you are using the !LOOP variable with SET !DATASOURCE_LINE to control the current line/row of an input file and you want it to skip the header row.

Value iMacros Browser IE Plug-in Firefox Chrome

Any integer 1,2,3,4,5,....

Set By

[X] Internal

[X] SET

Internal means that the iMacros program itself sets the value of the variable during program run. SET means that the user can set this value via the SET command inside a macro.

Examples

* There is a demo video.
* Related example macros: Demo-Slideshow

Notes

  • The command to explicitly set the value of !LOOP is only executed once. So if you use the following to e.g. skip the header row of an input file, it will be ignored for every loop run except the first one.
SET !LOOP 2 
  • The !LOOP variable is never set as a result of calling a macro using the scripting interface (iimPlay). It is only set when playing the macro directly from the sidebar or from the command line using the -loop switch. To loop a macro using the scripting interface, the user must setup the loop using whatever loop construct is appropriate for the scripting/programming language they are using, and pass in their own user-defined loop variable to the macro. See VBS looping for a quick VBScript example.

See Also

Input from Comma Separated Data (CSV) File, Demo-Loop-Csv-2-Web, VBS looping, Loop after Query or Login