• 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: exit this repeat loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exit this repeat loop


  • Subject: Re: exit this repeat loop
  • From: "Scott Babcock" <email@hidden>
  • Date: Wed, 14 Sep 2005 14:49:35 -0700
  • Thread-topic: exit this repeat loop

Here's real abuse of the 'error' event:

try
    repeat with i from 1 to 10
        repeat with j from 1 to 10
            error "true" number 1
        end repeat
    end repeat
on error errmsg number errnum
    try
        return {errmsg as boolean, errnum as boolean}
    end try

    error errmsg number errnum
end try

By setting the error message to "true" or "false", and by setting the
error number to 0 or 1, you can exit your loop with 4 different "normal"
states. Since you re-throw any states you don't recognize as "normal"
(because it can't be coerced to boolean), you don't risk masking a real
error.

Of course, you could also set the message to a string that can be
coerced to a number. That would afford you a huge number of "normal"
exit states.


> -----Original Message-----
> Date: Tue, 13 Sep 2005 15:40:01 -0400
> From: "Mark J. Reed" <email@hidden>
> Subject: Re: exit this repeat loop
> To: Christopher Nebel <email@hidden>
> Cc: AppleScript Users <email@hidden>
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> It's the standard way of doing it in Ruby.  Of course, Ruby
> distinguishes between the "exceptions" that you use for this (via
> throw/catch) and the "errors" that arise from actual problems (via
> raise/rescue).
>
>
> On 9/13/05, Christopher Nebel <email@hidden> wrote:
> > On Sep 12, 2005, at 1:59 PM, Matt Neuburg wrote:
> >
> > > I am very fond of throwing (and handling) an error as a way of
> > > jumping out
> > > to any desired level. I regard this as elegant.
> >
> > That would depend on how much you subscribe to the notion of
> > "exceptions are only for exceptional conditions".  In languages with
> > richer flow control, using exceptions this way is generally
> > considered an abuse.  AppleScript being what it is, I'd consider it
> > at least not unreasonable.
> >
> >
> > --Chris Nebel
> > AppleScript and Automator Engineering
> >
> >  _______________________________________________
> > Do not post admin requests to the list. They will be ignored.
> > Applescript-users mailing list
(email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> users/email@hidden
> >
> > This email sent to email@hidden
> >
>
>
> --
> Mark J. Reed <email@hidden>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Scripting Image Events - some kind of bug ?
  • Next by Date: Re: Q: Add one pixel on right / GraphicConverter
  • Previous by thread: Re: exit this repeat loop
  • Next by thread: FileMaker Pro 7-8: Getting Files into Containers
  • Index(es):
    • Date
    • Thread