Command:/for

From the wonderful RedGuides Wiki

This command is added by MacroQuest

Syntax Key
Notation Description
Text without brackets or braces Required items
<Text inside angle brackets> Placeholder for which you must supply a value
[Text inside square brackets] Optional items
Vertical bar (|) Separator for mutually exclusive items; choose one
{Text | inside | braces} Set of required items; choose one
Ellipsis () Items that can be repeated
Syntax /for <varname> <initial-value> to|downto <final-value> [step <interval>]
Description This runs all commands between the /for line and the /next line, after which it increments/decrements the varname number by step number (default is 1) before running through the commands again. It will keep doing this until the varname number equals the to or downto number. You can end a /for loop immediately with /break or try the next iteration with /continue.

Options

Examples

  • Simplest
/declare varname int local
/for varname 1 to 5
    /echo ${varname}
/next varname

Will output:

1
2
3
4
5
  • Using /continue
/declare varname int local
/for varname 1 to 5
   /if ({$varname} == 3) /continue
   /echo ${varname}
/next varname

Will output:

1
2
4
5
  • Using /break
/declare varname int local
/for varname 1 to 5
    /if (${varname} == 3) /break
    /echo ${varname}
/next varname

Will output:

1
2
  • With a pre-defined ending variable
/declare loopend int local 5

/declare varname int local
/for varname 1 ${loopend}
  /echo ${varname}
/next varname

Will output:

1
2
3
4
5

See also