• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Skip a step in a repeat loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Skip a step in a repeat loop


  • Subject: Re: Skip a step in a repeat loop
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 30 Aug 2001 08:39:25 -0700

On 8/30/01 8:06 AM, "Arthur J Knapp" <email@hidden> wrote:

> In fact, AppleScript could really use a statement for iteration skipping.
> The real problem, (as I see it), is that the work-arounds others have posted
> all introduce yet another darn level of indentation:
>
> tell application "Whatever"
>
> if (whatever) then
>
> repeat with whatever in whatever
>
> if (whatever) then
>
> ...
>
> I am so sick of looking at lines of AppleScript code that have 15 to 20
> tabs in front of them. I favor a loop-continue statement for the whitespace
> savings alone... ;-)


Somebody here (I forget whom - perhaps Nigel will remember) [posted a really
brilliant workaround - nay, solution - to this problem. I use it all the
time. As you say, the if/then stuff gets horribly messy, especially when
you're trying to exit long before the end of the repeat loop. Here:

repeat with i from 1 to 100 -- or whatever, any sort of repeat loop

repeat 1 times

--blah blah
if something  "what you want" then
exit repeat --goes on to next iteratio
end if
--lots of blah blah
--tons of scripting
end repeat
end repeat

And if you also need to get out of the "real" repeat loop higher up the
script (doesn't happen very often, but just in case - my own contribution
today):


repeat with i from 1 to 100 -- or whatever, any sort of repeat loop

repeat 1 times
set realExit to false
--blah blah
if someParam = "satisfied" then
set realExit to true
exit repeat
end if
--blah blah
if something  "what you want" then
exit repeat --goes on to next iteration
end if
--lots of blah blah
--tons of scripting
end repeat
if realExit then exit repeat
end repeat


--
Paul Berkowitz


  • Follow-Ups:
    • Re: Skip a step in a repeat loop
      • From: "Serge Belleudy-d'Espinose" <email@hidden>
References: 
 >Re: Skip a step in a repeat loop (From: Arthur J Knapp <email@hidden>)

  • Prev by Date: Re: Scripting Newbie
  • Next by Date: Re: New user
  • Previous by thread: Re: Skip a step in a repeat loop
  • Next by thread: Re: Skip a step in a repeat loop
  • Index(es):
    • Date
    • Thread