• 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 repeat abuse;-)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: exit repeat abuse;-)


  • Subject: RE: exit repeat abuse;-)
  • From: Scott Babcock <email@hidden>
  • Date: Thu, 14 Jan 2010 22:39:09 +0000
  • Thread-topic: exit repeat abuse;-)

Yes, I'm quite fond of the nested "repeat 1 times" structure as a substitute for the 'C' language 'continue' statement:

    set done to false
    repeat until done
        repeat 1 times
            delay 1

            set not_ready to check_if_ready(1)
            if not_ready then exit repeat

            -- do some stuff here

            set not_ready to check_if_ready(2)
            if not_ready then exit repeat

            -- do some other stuff

            set done to check_if_done()
        end repeat
    end repeat

Any other structure that I can think of for handling this sort of logic involves nested conditionals, and this can get very deep very quickly.

Within the bounds of a "repeat 1 times" block, the "exit repeat" statement is essentially a "goto" that takes you to the line following the "end repeat". I know that the discussions around the evils of "goto" can get pretty heated, but the judicious use of "goto" can greatly simplify the flow of logic. (See Also - 'return' from the middle of a function)

-----Original Message-----

Date: Thu, 14 Jan 2010 08:26:09 -0800
From: "email@hidden" <email@hidden>
Subject: Re: exit repeat abuse;-)
To: airdrummer <email@hidden>
Cc: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=us-ascii

Well, of course that's the simplest example of the concept possible.

Nearly all the scripts I have that use that method have numerous conditions that would return to the top of the repeat loop from several points inside.

Much cleaner if if done with the double repeat method.

ES

On Jan 14, 2010, at 6:54am, airdrummer wrote:

>>  repeat 1 times
>>     do stuff
>>     If a is true then exit repeat
>> --do stuff you want to do if a is false
>>   end repeat
>
> uh, isn't that better expressed as:
>
>      -- do stuff
>      If a is false then
> 	 --do stuff you want to do if a is false
>      end if

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: how?
  • Next by Date: scripting Magic Mouse
  • Previous by thread: Re: exit repeat abuse;-)
  • Next by thread: scripting Magic Mouse
  • Index(es):
    • Date
    • Thread