From: Susan Sash Date: 2006-05-16T02:48:42+09:00 Subject: iterator/array question Is there a way to iterate through an array, getting the index and the object at the same time? For instance, right now I know two ways of going through an array: array.each do |element| print element end for i in 0..(array.size - 1) do |i| print array[i] end Is there a way to mix these two together? As in something like array.each do |element, i| print element.to_s + "is at index " + i.to_s end without maintaining a counter through the array? (Without doing this: index = 0 array.each do |element| print element.to_s + "is at index " + index.to_s index += 1 end) Thanks! -- Posted via http://www.ruby-forum.com/.