Language Guide
CHAPTER 7
Control Statements
194 Repeat Statements
Repeat Statements 7
Repeat statements are used to create loops, or groups of repeated statements,
in scripts. There are several types of Repeat statements, which differ in the way
they specify when the repetition stops.
For example, the following Repeat statement performs the same action a
specified number of times:
repeat 2 times
beep
end repeat
The following Repeat statement performs the same actions while a specific
condition is true:
tell application "Scriptable Text Editor"
set numberOfWindows to (count windows)
repeat while numberOfWindows > 0
close front window
set numberOfWindows to (count windows)
end repeat
end tell
You can also specify an infinite loop, which is a Repeat statement that does
not specify when the repetition stops. You can use an Exit statement within
an infinite loop or any other Repeat statement to immediately exit the
Repeat statement.