Re: Avoiding repetition
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.