From: Dark Ambient Date: 2006-07-04T03:39:57+09:00 Subject: Re: Array loops: new thread Cool guys, thank you. I was not aware of include and had just gone down the array class instance methods prior to asking for help. Leads me to conclude I should have read through it 3x not once. Stuart On 7/3/06, brian.mattern@gmail.com wrote: > On Tue, Jul 04, 2006 at 03:27:07AM +0900, Dark Ambient wrote: > > I thought it would be better to start a new thread for my current > > issue, since the old one is filled with code in various stages. > > Apologies. Gives me a chance to ask more succinctly regarding the > > core issue. > > > > This is just an example. > > I have 2 arrays > > > > firstarray = ['1','2,'3','4','5'] > > secondarray = ['1','2','3','4','5','6','7'] > > > > I'm looping through firstarray.each do |x| > > go through some blocks. At some point, either the start of the outter > > array or somewhere down in the conditional statements I need to find > > out if elements of firstarray are in secondarray. The only way I can > > fathom doing this right now is by starting another loop, i.e. > > secondarray.each do |y|. Problem is this seems to create constant > > problems where the outter loop / [0] element is going through the > > entire inner loop before proceeding on. to it's next element. Maybe > > as someone suggested earlier today to me, to use break. Haven't had > > much luck with that yet. > > > > If this question makes sense, anyone have some suggestions , comments > > or anything else that might be helpful ? > > > > TIA > > Stuart > > > > How about something like: > > secondarray.each do |x| > if firstarray.include?(x) > // do something > end > end > > Brian > > >