Re: exit this repeat loop
Re: exit this repeat loop
- Subject: Re: exit this repeat loop
- From: Christopher Nebel <email@hidden>
- Date: Mon, 12 Sep 2005 11:37:31 -0700
On Sep 12, 2005, at 9:51 AM, Mark J. Reed wrote:
On 9/12/05, Robert Poland <email@hidden> wrote:
repeat with index from 1 to the 10
set optionDown to testOption() -- line 1
if optionDown then return -- line 2
Well, you don't need the set, right? Just
if testOption() then return
Another thing is that since you're not using "index" anywhere, you
could just say "repeat 10 times".
And this does way too much:
on testOption()
if (keys pressed) contains "option" then
beep 2
set optionDown to true
return optionDown
else
set optionDown to false
end if
end testOption
How about this?
on testOption
(keys pressed) contains "option"
end testOption
Personally, I prefer to be explicit by saying "return ...", but
either works. However, the short version isn't semantically
equivalent to the original, because it doesn't beep. Now, you could
argue that so what, the main one is beeping too and how are you going
to tell them apart, but it's something to keep in mind. On the other
hand, now that you can do (most) of this handler in one line, why do
you need a handler? (The obvious answer is "to call somewhere else",
but if you're not...) So, rewritten:
repeat 10 times
if (keys pressed) contains "option"
beep 2
return -- or "exit repeat"
else
beep
delay 1
end
end
--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:
This email sent to email@hidden