From: Logan Capaldo Date: 2006-06-29T05:41:03+09:00 Subject: Re: Looping through 2 arrays On Jun 28, 2006, at 4:34 PM, Dark Ambient wrote: > I'm trying to loop through 2 arrays, and notice some odd behaviour, > probably because the syntax is not correct > > unsorted.each do |x| > sorted.each do |y| > puts 'this is que_words ' + x + '.' > puts 'this is s_words ' + y + '.' > end > end > > I added the 'puts' in as I'm trying to build a bigger block of code > and trying to take it one step at a time with some checking in place. > unsorted has elements, sorted is empty. > > When I run the above, nothing is output. When I comment out the > sorted loop, unsorted outputs it's elements. Would having an empty > array effect the output of unsorted or is this just plain wrong ? > > Stuart > If sorted is empty it, never enters the sorted.each block, which is where all the output is. Try this unsorted.each do |x| puts 'this is que_words ' + x + '.' sorted.each do |y| puts 'this is s_words ' + y + '.' end end