Language Guide
CHAPTER 7
Control Statements
Repeat Statements 201
Repeat With (loopVariable) From (startValue) To (stopValue) 7
In the Repeat With (loopVariable) From (startValue) To (stopValue) form of the
Repeat statement, the looping variable is an integer that is increased by a
specified value after each iteration of the loop. The loop terminates when
the value of the variable is greater than a predefined stop value.
SYNTAX
repeat with loopVariable from startValue to stopValue [ by stepValue ]
[ statement ]...
end [ repeat ]
where
loopVariable is used to control the number of iterations. It can be any
previously defined variable or a new variable you define in the Repeat
statement (see “Notes”).
startValue (an integer) is the value assigned to loopVariable when the loop
is entered.
stopValue (an integer) is the value of loopVariable at which iteration ends.
Iteration continues until the value of loopVariable is greater than the value
of stopValue.
stepValue (an integer) is the value added to loopVariable after each iteration of
the loop. The default value of stepValue is 1.
statement is any AppleScript statement.
EXAMPLE
The following example numbers the paragraphs of a document with the Repeat
With (loopVariable) From (startValue) To (stopValue) form of the Repeat statement.
tell document "List"
repeat with n from 1 to (count paragraphs)
set paragraph n to (n as string) & " " & paragraph n
end repeat
end tell