Re: Silly repeat question
Re: Silly repeat question
- Subject: Re: Silly repeat question
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 26 Aug 2010 17:53:19 -0400
OK, I totally failed to convey my intent here. I was contrasting the
use of "exit repeat" with that of condition variables, by way of
analogy to show why "next repeat" would also be a useful feature.
Sadly, it's a feature that AS doesn't currently have. Sorry for the
botched communication.
Anyway.
Alex:
> My brain must be dented. I'm not seeing something here.
> No way to avoid the nesting of my code block?
Right. Since there's no "next repeat" command, you have no choice but
to use some sort of nested construct. Either an if/else around the
post-"next repeat" code, or something else just inside the repeat.
The canonical example (page 226 in the original edition of AS:TDG) is
an inner "repeat 1 times", in which "exit repeat" stands in for "next
repeat". The drawback is that you lose the ability to do an actual
"exit repeat" to leave the outer loop, if you need to do that as well.
Another option is to use a try block and a pseudo-error made up for
the occasion, the throwing of which stands in for "next repeat", while
"exit repeat" still does its usual job.
As far as I know, those are the tools at your disposal with which to
hammer in this particular nail.
On Thu, Aug 26, 2010 at 4:30 PM, Mark J. Reed <email@hidden> wrote:
> On Thu, Aug 26, 2010 at 3:32 PM, Alex Zavatone <email@hidden> wrote:
>> Hmmm. This doesn't seem much better than an if/then statement to check a condition. Is it? Am I missing something?
>
> You're missing the ability to leave the loop in the middle without
> having to bury the rest of it in an else clause. Consider this:
>
> repeat while someCondition
> do something one
> if bailout1 then
> set someCondition to false
> else
> do something two
> if bailout2 then
> set someCondition to false
> do something three
> if bailout3 then
> set someCondition to false
> do something four
> end if
> end if
> end if
> surprise!
> end repeat
>
> versus this:
>
> repeat while someCondition
> do something one
> if bailout1 then
> exit repeat
> end if
> do something two
> if bailout2 then
> exit repeat
> end if
> do something three
> if bailout3 then
> exit repeat
> end if
> do something four
> end repeat
>
> You can continue to add decision points without your loop body walking
> off the right of the page. Plus you don't have surprises like the
> "surprise!" in the first example, which gets executed even if you hit
> the first "bail out" point.
>
--
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:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden