• 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: Avoiding repetition
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Avoiding repetition


  • Subject: Re: Avoiding repetition
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 15 Jul 2004 12:55:17 -0700

On 7/15/04 12:14 PM, "Bernard Azancot" <email@hidden> wrote:

> till another basic newbie question:
>
> The following script has no problem. I just would like to know if it is
> possible to improve its "coding style" .
>
>
> (* Pseudo Script Start *)
>
> -- Note that "action" is the action performed, always the same
> (delete/copy), but in a different folder each different day of the week
> (backup purpose)
>
> If myday = Monday then
> action to folder A
>
> else If myday = Tuesday then
> action to folder B
> ...
> ...
> else if myday = Sunday then
> action to folder G
>
> (* Pseudo Script End *)
>
>
>
> Is there a way to avoid repeating 7 times the same boring code lines
> with 2 bound variables (day and folder) ?


If 'action' takes several lines, put it in a handler with a parameter (x)
where x gets replaced by A, B, c, or 'folder A, folder B, folder C.
Otherwise , if it's just a line, no need. You can replace the construction
this way:

-------------------
set weekDayList to {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
Sunday}
set folderList to {A, B, C, D, E, F, G}

repeat with i from 1 to 7
if myDay = item i of weekDayList then
action folder (item i of folderList)
exit repeat
end if
end repeat

----------------


However, this is actually going to be less efficient (not that it matters
much with something so simple) than your original. since two lists have to
be built (could be stored as properties, of course) and iterated. There's
nothing much wrong with your original method.
--
Paul Berkowitz
_______________________________________________
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.


  • Follow-Ups:
    • Re: Avoiding repetition
      • From: Nigel Smith <email@hidden>
    • Re: Avoiding repetition
      • From: "John W. Baxter" <email@hidden>
References: 
 >Avoiding repetition (From: Bernard Azancot <email@hidden>)

  • Prev by Date: Re: Record Access OSA by Ed email@hidden
  • Next by Date: Re: Photostitch Dictionary
  • Previous by thread: Avoiding repetition
  • Next by thread: Re: Avoiding repetition
  • Index(es):
    • Date
    • Thread