Language Guide

CHAPTER 7
Control Statements
202 Repeat Statements
NOTES
You can use an existing variable as the looping variable in a Repeat statement
or define a new one in the Repeat statement. You cannot change the value of
the looping variable in the loop body. The variable is undefined after the loop
has been executed, but you can redefine it outside the loop.
AppleScript evaluates startValue, stopValue, and stepValue when it begins
executing the loop and stores the values internally. If you change the values
in the body of the loop, it has no effect on the execution of the loop.
Repeat With (loopVariable) In (list) 7
In the Repeat With (loopVariable) In (list) form of the Repeat statement, the
looping variable is a reference to an item in a list. The number of iterations is
equal to the number of items in the list. In the first iteration, the value of the
variable is item 1 of list (where list is the list you specified in the first line of
the statement), in the second iteration, its value is item 2 of list, and so on.
SYNTAX
repeat with loopVariable in list
[ statement ]...
end [ repeat ]
where
loopVariable is any previously defined variable or a new variable you define in
the Repeat statement (see “Notes”).
list is a list or a reference (such as words 1 thru 5) whose value is a list. list
can also be a record; AppleScript coerces the record to a list (see “Notes”).
statement is any AppleScript statement.
EXAMPLE
The following example numbers the paragraphs of a document with the Repeat
With (loopVariable) In (list) form of the Repeat statement. The value of the