Re: "Next" in Repeat?
Re: "Next" in Repeat?
- Subject: Re: "Next" in Repeat?
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 23 Jan 2001 08:59:46 -0800
On 1/23/01 7:26 AM, "Steve Ivy" <email@hidden> wrote:
>
I'm still kinda new to AppleScript - is there a way to break out of the
>
current loop in a repeat statement and skip to the next one?
>
>
Something like:
>
>
repeat with i in {1,2,3}
>
if i is "2"
>
next repeat
>
else
>
log (i)
>
end if
>
end repeat
>
>
???
>
Somebody. I'm afraid I forget who, once posted an ingenious solution here to
meet the lack of a "next repeat" function in AppleScript. Sometimes, you
just can't put an if/then or try/error block at the bottom of your repeat
loop loop, and there are good reasons not to put the whole remaining segment
of the commands into such a block. Do this: immediately inside the repeat
loop, put another one:
repeat with i from 1 to num -- whatever the number of items is
set x to item i of yourList
repeat 1 times
-- do your stuff
if --something or other
exit repeat
end if
-- continue more stuff
end repeat
end repeat
That 'exit repeat' just gets you out of that particular iteration, and you
then continue the main repeat loop with the next item. Great, no? I use it
all the time. I wish I could remember who suggested it - it was a lurker,
not a regular contributor. Perhaps Nigel Garvey remembers - he was similarly
impressed.
--
Paul Berkowitz