Re: "Next" in Repeat?
Re: "Next" in Repeat?
- Subject: Re: "Next" in Repeat?
- From: Emmanuel <email@hidden>
- Date: Tue, 23 Jan 2001 18:56:45 +0100
At 16:26 +0100 23/01/01, Steve Ivy 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
This is a long-standing question.
As far as my experience can tell, there are two alternative solutions.
1 - Call a handler
repeat with i in {1,2,3}
ProcessLoop(i)
end repeat
on ProcessLoop(i)
if i is "2"
return
else
log (i)
end if
end
2 - (Convenient for long loops) Throw an error
repeat with i in {1,2,3}
try
if i is "2"
error "next repeat"
else
log (i)
end if
on error s number n
if s is not "next repeat" then error s number n -- be transparent
end
end repeat
HTH
Emmanuel