Re: how?
Re: how?
- Subject: Re: how?
- From: has <email@hidden>
- Date: Thu, 14 Jan 2010 07:35:06 +0000
Adam Morris wrote:
> FYI this is a programmer's way of writing code that's partially a comment.
> Take a look at the repeat statement:
>
> repeat until ValidInput = true
>
> That means: "I'm going to keep asking the user for valid input." More
> experience in scripts will show you that you use this trick often: "Repeat
> forever until I get valid input."
No, it's just schlonky code. Author probably started out meaning to write it in proper structured programming style, because having exit conditions buried in the middle of the repeat block rather than at the start makes it harder to read:
on DoSomething()
set ValidInput to false
repeat until ValidInput
-- Do some stuff
if SomeConditionIsMet then
set ValidInput to true
else
-- Do some more stuff
end if
end repeat
return ResultValue
end DoSomething
then at some point found it was, on balance, less convoluted just to exit mid-loop using a return, but forgot to clean up all the code. Easy done, and nothing a quick tidy won't solve:
on DoSomething()
repeat
-- Do some stuff
if SomeConditionIsMet then return ResultValue
-- Do some more stuff
end repeat
end DoSomething
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
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