repeat until end [repeat] |
|
Syntax
Repeat until trueBoolean
(* code statements *)
end repeat
Description
This form of repeat takes the
until keyword and a boolean
expression, as in: repeat until countVar is true.
The statements that are contained within repeat
until...end repeat will
continue to execute until the boolean conditional
expression is true. If the expression following
until is true, the
repeat loop is terminated and execution resumes
with the statement following end repeat. You could
also exit this repeat loop using the
exit statement (see exit). Note
that when repeat until
encounters a true value, the loop is immediately
ended; its enclosed statements are not executed.
Examples
This AppleScript shows a repeat until statement
that also contains an exit statement:
set theCount to 0
repeat until (theCount = 5)
if theCount = 4 then exit repeat
set theCount to theCount + 1
log theCount
end repeat
This code increments a theCount
integer variable by one with each cycle through
the loop. The code includes a simple if statement
that exits the repeat loop once the
theCount variable reaches 4. Without the
exit statement, the variable would reach 5; the
expression: theCount = 5 would return
true, and the repeat
until loop would terminate. We keep track of the
value of theCount with a log
theCount statement. This displays all of the
theCount values in Script
Editor's Event Log window.
|