This article on MacTech summarizes the loop flow control structures in AppleScript which apparently amounts to the “repeat” command.
repeat
-- code
end repeat
this will repeat indefinitely but you can exit the repeat within such a block by adding something like this:
if stopMe = true then
exit repeat
end if
You can also repeat a fixed number of times:
repeat 5 times
-- code
end repeat
You can also repeat until some condition:
repeat while keepGoing = true
-- code
end repeat
repeat until stopMe = true
-- code
end repeat
Finally there is a kind of repeat which is familiar to anyone who has used increments in for loops in other programming languages:
repeat with x from 1 to 10
-- code which can refer to the number x which increases with each repeat
end repeat
3 Comments
Simple, clean advice. Thanks.
Really nice site, mate!
There’s also the “repeat with «item» in «list»” form.
excellent list
I had a look for something like this:
repeat until exists sheet 1 of window 1 but no more than 20 times
like this:
repeat 20 times
delay 0.1
if exists sheet 1 of window 1 then
exit repeat
end if
end repeat