Team LiB   Previous Section   Next Section
repeat end [repeat]

Syntax

repeat

   if someTrueCondition then exit repeat

end repeat

Description

repeat without any conditional statements associated with it results in an infinite loop. In most cases, you need to use an exit statement to terminate the loop and resume execution with the statement that follows end repeat. This statement begins with repeat on its own line and finishes with an end or an end repeat (the repeat part of end repeat is optional). All of the statements that should execute within the loop appear between the repeat and end repeat lines. You can nest repeat loops within each other.

Examples

This AppleScript shows one repeat loop nested within another. It also illustrates that the exit statement only exits the repeat statement in which exit is contained. So the example actually needs two exit statements to emerge from its repetition purgatory:

repeat -- outer repeat loop

   repeat -- beginning of inner repeat loop

      set userReply to the text returned of¬

      (display dialog¬

         "Want to get out of inner endless loop?" default  answer "")

   if userReply is "yes" then exit repeat

   end repeat

   set userReply to the text returned of¬

   (display dialog "Want to get out of outer endless loop?" default ¬

   answer "")

   if userReply is "yes" then exit repeat

end repeat
    Team LiB   Previous Section   Next Section