From: Jose Hales-Garcia Date: 2009-12-13T23:19:49+09:00 Subject: Re: Code block for element comparison in an array? --Apple-Mail-1755--1061074577 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit On Dec 13, 2009, at 3:27 AM, Derek Cannon wrote: > for(int i=0; i < array.length; i++) { > for(int j=i+1; j < array.length; j++) { > // Compare array[i] with array[j] > } > } Here are a couple ways I could think to do it... #method 1 a.length.times do |i| (i+1).upto(a.length) do |j| # Compare a[i] and a[j] end end #method 2 a.each_with_index do |e1,i| a[(i+1)..a.length].each do |e2| # Compare e1 and e2 end end ....................................................... Jose Hales-Garcia UCLA Department of Statistics jose@stat.ucla.edu --Apple-Mail-1755--1061074577--