• 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: Best practices- nested loops or handlers or both
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best practices- nested loops or handlers or both


  • Subject: Re: Best practices- nested loops or handlers or both
  • From: "Adam K. Wuellner" <email@hidden>
  • Date: Mon, 1 Nov 2004 12:51:46 -0600

On Nov 1, 2004, at 12:03 PM, Eric Geoffroy wrote:

d is date in list
Loop 1 tests d and if it's a weekend, bumps it to next day.
Loop 2 tests d and if it's a holiday, bumps it to next day.

Now those two loops need to be nested in case loop 2 moves d to a weekend.

... and, obviously, it doesn't stop there. If you start on Thanksgiving, for example, you'll need loop 2 twice and loop 1 twice:
(Thursday -loop 2-> Friday -loop 2-> Saturday -loop 1-> Sunday -loop 1-> Monday)


What you want, probably, is a recursive handler that test for both weekend-ness and holiday-ness, increments the date if either are true, and calls itself again to see if it should continue processing.

So, say you've got good isWeekend(d) and isHoliday(d) handlers, each returning true or false. Then you can create a recursive handler to increment the 'd' parameter until both tests are false. Consider this pseudo code:

on getNextBusinessDay(d)
	if isWeekend(d) or isHoliday(d) then
		d = d + 1
		getNextBusinessDay(d)
	end if
	return d
end getNextBusinessDay

If d is either a holiday or a weekend, then it gets bumped, and we call the handler again. If it's still either holiday or weekend, then it gets bumped, and we call the handler again... If at any point (iteration) d is not a holiday or weekend, the if...end if block is passed over and the value d is returned from the handler.

_______________________________________________
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


  • Follow-Ups:
    • Re: Best practices- nested loops or handlers or both
      • From: Eric Geoffroy <email@hidden>
    • Re: Best practices- nested loops or handlers or both
      • From: Eric Geoffroy <email@hidden>
References: 
 >Best practices- nested loops or handlers or both (From: Eric Geoffroy <email@hidden>)

  • Prev by Date: Best practices- nested loops or handlers or both
  • Next by Date: Re: Inheritance and Loaded Libraries
  • Previous by thread: Best practices- nested loops or handlers or both
  • Next by thread: Re: Best practices- nested loops or handlers or both
  • Index(es):
    • Date
    • Thread