Language Guide
CHAPTER 7
Control Statements
Repeat Statements 203
reference paragraphs (the paragraphs of document "List") is a
list of the paragraphs in the document.
tell document "List"
set paragraphNum to 1
repeat with n in paragraphs
set paragraph paragraphNum to
(paragraphNum as string) & " " & contents of n
set paragraphNum to paragraphNum + 1
end repeat
end tell
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 loopVariable in list as item 1 of list, item 2 of
list, item 3 of list, and so on until it reaches the last item in the list:
repeat with i in {1, 2, 3, 4}
set x to i
end repeat
--result: item 4 of {1, 2, 3, 4}
To get the value of an item in the list, you must use the contents of operator:
repeat with i in {1, 2, 3, 4}
set x to contents of i
end repeat
--result: 4
If the value of list is a record, AppleScript coerces the record to a list by
stripping the property labels. For example, {a:1, b:2, c:3} becomes
{1, 2, 3}.