If you want the first 10, just do this: ary[0..9] Sent from my iPhone On 30/01/2009, at 9:34 AM, Tim Hunter <TimHunter / nc.rr.com> wrote: > Dan No wrote: >> So painfully basic, but I'm just starting Ruby and am coming to it >> from >> C/C++/Java, etc. and some of the syntax is unnatural to me, and yes, >> I've tried Google. I have an array of things and I want to access the >> first 10...how do I do that? >> for thing in things #(how do I set the beginning and end of the >> loop?) >> #do something >> end > > Usually collections define an each method. Each call into the block > gets the next element in the collection. You don't have to worry > about the beginning and end of the loop. The each method and its > friends are considered the most idiomatic. > > ary.each {|element| ...} > > Or if you just want the equivalent of a C for loop, use upto. The > block argument is the current count, starting with 'start': > > start.upto(finish) {|n| ...} > > Also there's step, which lets you use an increment other than 1: > > start.step(finish, incr) {|n| ...} > > It really depends on what you want to do. > > -- > RMagick: http://rmagick.rubyforge.org/ >