Re: Help with recursion
Re: Help with recursion
- Subject: Re: Help with recursion
- From: Walter Ian Kaye <email@hidden>
- Date: Tue, 11 May 2004 18:14:53 -0700
At 05:33p -0700 05/11/2004, Michelle Steiner didst inscribe upon an
electronic papyrus:
on get_date()
set target to false
repeat until target is true
set target_date to text returned of (display dialog "enter the
target date" default answer "")
try
set target_date to date target_date
on error
get_date()
end try
set target to true
end repeat
return target_date
end get_date
If a correct entry is made the first time, the script works, but if
there is an error the first time, and the script gets another input,
the results of the first attempt are returned.
I see what the problem is; the incorrect entry is stored, and as the
recursive loop unwinds, the first entry is the one that remains.
How do I fix it?
Why use recursion at all? It's not necessary for this; the repeat
loop is all you need.
on get_date()
repeat
set target_date to text returned of (display dialog "enter the
target date" default answer "")
try
set target_date to date target_date
exit repeat
on error
--nut'n; we just gonna loop till the end luser gets it right
end try
end repeat
target_date
end get_date
"The optimist proclaims that this is the best of all possible worlds ;
and the pessimist fears this is true." --James Branch Cabell
Funny cuz it's two different worlds but sounds like just one. :-)
-boo
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.