From: Seebs Date: 2009-12-13T23:25:04+09:00 Subject: Re: Code block for element comparison in an array? On 2009-12-13, Derek Cannon wrote: > I'm new to Ruby and I can't think of how to do this! I would like each > element in an array to compare itself with all its proceeding elements. Why? > For those who don't understand, I think the Java/C++ equivalent would > be: > for(int i=0; i < array.length; i++) { > for(int j=i+1; j < array.length; j++) { > // Compare array[i] with array[j] > } > } I notice that you don't DO anything with the comparison. What's the point? If you're trying to verify that the array is sorted, you can do this with a LOT fewer operations... -s -- Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!