From: Benoit Daloze Date: 2009-12-13T23:19:51+09:00 Subject: Re: Code block for element comparison in an array? --0016e65b60a23b9aaa047a9cd95d Content-Type: text/plain; charset=ISO-8859-1 Here the solution with Integer#upto(n), as mentioned by Robert. 0.upto(array.length-1) { |i| (i+1).upto(array.length-1) { |j| // Comparison here! } } And the first loop could be replace by array.length.times { |i| } Or even better, array.each_index { |i| } That looks more rubyish ... P.S.: You can use 0...array.length instead of 0..array.length-1 2009/12/13 Derek Cannon > Ah, I figured it out... For anyone who is interested the answer is: > > for i in 0..array.length-1 > for j in i+1..array.length-1 > // Comparison here! > end > end > > -- > Posted via http://www.ruby-forum.com/. > > --0016e65b60a23b9aaa047a9cd95d--