Farrel Lifson <flifson / cs.uct.ac.za> writes:

> For a non numeric iterator is there a way to find out how many times
> the iterator has looped so far?
> 
> For instance I have an array of strings and I want to indent
> everything except the 1st string. Currently I have to do it like
> this
> 
> i = 0
> array.each{|element|
> 	print "\t" unless i = 0
> 	i = i+1
> 	print element,"\n"
> }

You could use each_with_index:


    array.each_with_index do |element, index|
       print "\t" unless index.zero?
       puts element
    end

Or, you could use join, which is probably a better way of expressing
it. 

   puts array.join("\n\t")


Regards



Dave