Language Guide

CHAPTER 7
Control Statements
Repeat Statements 195
Here’s an example of a Repeat statement with an Exit statement:
tell application "Scriptable Text Editor"
set numberOfWindows to (count windows)
set i to 1
repeat
if i > numberOfWindows then
exit
end if
print window i
set i to i + 1
end repeat
end tell
More elaborate forms of the Repeat statement use looping variables that you
can refer to in the body of the loop. Here’s an example:
tell application "Scriptable Text Editor"
set contents of front window to ""
set selection to "David Numberman's Top Ten Numbers for Lists
"
repeat with n from 1 to 10
copy (n as string & ". " & n as string & "
" ) to n
select end of front window
set selection to n
end repeat
end tell