Re:loops
Re:loops
- Subject: Re:loops
- From: Nigel Garvey <email@hidden>
- Date: Fri, 15 Feb 2002 15:05:57 +0000
Michelle Steiner wrote on Thu, 14 Feb 2002 12:32:59 -0700:
>
repeat until <condition>
>
-- stuff
>
end repeat
>
>
This starts out with a false condition and the loop continues until the
>
condition becomes true.
>
>
repeat while <condition>
>
stuff
>
end repeat
>
>
This starts out with a true condition and the loop continues until the
>
condition becomes false.
In AppleScript, the exit conditions for both these forms are tested at
the tops of the loops and the instructions within the loops are not
carried out if the conditions are already met. This differs from the
versions of BASIC to which I was first exposed, where 'repeat until' made
a virtue of being tested at the *end* of the loop, so that the
instructions within the loop would always be executed at least once. By
and large, I think I prefer the AppleScript implementation.
Another nice, similar feature of AppleScript loops is that if they can't
be executed at all for numerical reasons, they're simply not executed.
Examples:
set myList to {}
repeat with thisItem in myList
...
set anyNumberLessThanOne to -7
repeat anyNumberLessThanOne times
...
set myList to {}
repeat with i from 1 to (count myList)
...
This often saves having to check previous results before carrying out
loops based on them.
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.