Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 7 - Control Statements / Repeat Statements


Repeat (forever)

The Repeat (forever) form of the Repeat statement is an infinite loop. The only way to exit the loop is by using an Exit statement.

SYNTAX
repeat
   [ statement ]...
end [ repeat ]
where

statement is any AppleScript statement.

This is an infinite loop; you must use an Exit statement to exit the loop
(see page 204).

EXAMPLE
The following example numbers the paragraphs of a document. It uses the
Exit statement

if paragraphNum > numParagraphs then exit
to exit the loop.

tell document "List"
   set numParagraphs to (count paragraphs)
   set paragraphNum to 1
   repeat
      if paragraphNum > numParagraphs then exit
      set paragraph paragraphNum to (paragraphNum as string) & " " ÿ
         & paragraph paragraphNum
      set paragraphNum to paragraphNum + 1
   end repeat
end tell

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996