• 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 current repeat iteration
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Skip current repeat iteration


  • Subject: Re: Skip current repeat iteration
  • From: email@hidden (Michael Sullivan)
  • Date: Wed, 23 Oct 2002 14:20:52 -0400
  • Organization: Society for the Incurably Pompous

email@hidden (Paul Berkowitz) writes:
> On 10/22/02 11:58 AM, "Ken Grimm" <email@hidden> wrote:

> > On 10/22/02 1:11 PM, Paul Berkowitz at email@hidden didst forever and
> > always commit to the digital human communication archive:
> >
> >> repeat with i from 1 to n -- or any other repeat loop type
> >> repeat 1 times
> >
> > Should that be :
> >
> > repeat i times
> >
> > ??
>
> No it should not! Why would you want to go around the inner loop 100 times?
> If something meets the criteria for 'next repeat', whatever that may be
> (i.e. x = y, x /= y, or whatever) , exit the inner loop which gets you to
> the next main loop iteration. it doesn't really matter if you set a variable
> outside or inside the inner loop:

> set aList to {1,2,3,4,5,6,7,8}

> repeat with from 1 to n
>
> set someVariable to item i of aList
> repeat 1 times
> set newVariable to someVariable + 10
> if someVariable = 17 then
> display dialog "You've got a 7 there!"
> exit repeat
> end if
> end repeat
> set item i of aList to newVariable
> --57 more lines of script

> end repeat

This isn't quite right. For this trick to operate like "next repeat",
you need to put the 57 more lines of script inside the inner repeat
loop. The whole point is that you're trying to skip them on this
iteration of the main loop. Your code will always execute those 57
lines including when i is 7.

This trick, BTW, means that you can't use a *real* exit repeat for the
outer loop very easily.

I have to say that every time I've wanted next repeat, I've been able to
write around it in a way that was just as clear (if not clearer) as
using it. I'd call it syntactic sugar.

IMO, if you have such a complicated case structure, that adding one more
"else if" is a big problem, some refactoring may be in order.


Michael

--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
_______________________________________________
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.

References: 
 >Re: Skip current repeat iteration (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: Re: Eudora Settings was Re: User N...
  • Next by Date: My apologies for the double posting
  • Previous by thread: Re: Skip current repeat iteration
  • Next by thread: Re: Skip current repeat iteration
  • Index(es):
    • Date
    • Thread