Syntax

repeat while <condition>
  <repeatedCommands>
end repeat

repeat with <counterName> from <startNumber> [down] to <endNumber>
  <repeatedCommands>
end repeat

repeat while the mouse is down
  set the location of button "Slider" to item 1 of the mouseLoc,item 2 of the location of button "Slider"
end repeat

repeat with iconNumber from 1 to number of icons
  output the name of icon iconNumber & newline
end repeat

Explanation

The repeat command lets you repeatedly execute the same commands. You can either repeat while a certain condition is true, or you can make a number run in single steps through a range and have the commands executed for each step through the range. E.g. repeat with x from 1 to 3 will run the commands 3 times, the first time with x being 1, the second time with x being 2, and the last time with x being 3.

Parameters

condition

The condition to evaluate. As long as this condition is true, repeatedCommands will be run over and over again, otherwise the loop will stop and the commands after the end repeat will be executed.

repeatedCommands

The commands to execute as long as condition is true.

counterName

The name of the variable in which the current number will be written. This number changes with every time repeatCommands are executed. If you repeat from 1 to 3, this variable will be 1 the first time repeatCommands run, 2 the second time, 3 the third time.

startNumber

The number to start the loop at. This will be the first number used, and then 1 will be added to it each time.

endNumber

The number to end the loop at. This will be the last number used, and then the commands after end repeat will be done.

down

If you specify “down”, the numbers will be iterated in reverse. So you can start at 3 and end at 1, and on each iteration, 1 will be subtracted from the counter variable.