Re: "Next" in Repeat?
Re: "Next" in Repeat?
- Subject: Re: "Next" in Repeat?
- From: "Arthur J Knapp" <email@hidden>
- Date: Tue, 23 Jan 2001 15:52:18 -0500
>
Date: Tue, 23 Jan 2001 08:59:46 -0800
>
Subject: Re: "Next" in Repeat?
>
From: Paul Berkowitz <email@hidden>
>
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?
>
Somebody. I'm afraid I forget who, once posted an ingenious solution here to
>
meet the lack of a "next repeat" function in AppleScript.
>
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.
Oh, I'll take credit, I don't mind... (though I wouldn't describe myself
as a "lurker"). ;-)
Another method is to generate an error:
repeat with x from 1 to num
try
-- Stuff
if ( [skip the rest of the current loop] ) then
error "continue" -- any old error will do...
end if
-- More stuff
end try
end repeat
--
{
Arthur J Knapp, of STELLARViSIONs ;
http://www.STELLARViSIONs.com ;
mailto:email@hidden ;
"...well the rain falls down
without my help, I'm afraid
and my lawn gets wet,
though I withheld my consent..."
}