Re: How to step through two lists at the same time?
Re: How to step through two lists at the same time?
- Subject: Re: How to step through two lists at the same time?
- From: "Mark J. Reed" <email@hidden>
- Date: Sun, 19 Aug 2007 18:07:24 -0400
Since list1 and list2 are different sizes, what do you want to do for
the 5th and 6th iterations? Skip them? Have 5 and 6 with nothing?
Cycle back to 5+1a and 6+2a?
The general idiom for this sort of thing is to loop through the
indices rather than the lists, e.g.
set list1 to {1, 2, 3, 4, 5, 6}
set list2 to {"1a", "2a", "3a", "4a"}
set min to length of list1
if length of list2 is less than min then
set min to length of list2
end if
repeat with i from 1 to min
set a to item i of list1
set b to item i of list2
-- do stuff with a and b
end repeat
The above stops at the end of the shorter list; if you answered my
initial question differently, you'd need to modify the script.
On 8/19/07, Patrik B. <email@hidden> wrote:
> How do I do a repeat through two lists at the same time:
>
> Example I have two lists
>
> set list1 to {1,2,3,4,5,6}
>
> set list2 to {"1a","2a","3a","4a"}
>
> repeat with i in list1
> repeat with j in list2
> -- do action with 1 and 1a
> -- do action with 2 and 2a etc.-- the way the repeat is worded now is it will
> give me 1-6 with 1a and then 2a but I want to progress through both lists at
> the same time.
> end
> end
>
> repeat with i in list and j in list2 -- does not work
>
>
> Patrik
> _______________________________________________
> 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
>
--
Mark J. Reed <email@hidden>
_______________________________________________
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