Jeff Fry wrote: > Hi, > > I am brand new to ruby and liking it so far - particularly the watir > test libraries. I am comfortable with the Java for loop syntax (i=0, > i<4, i++) and haven't found something in ruby that feels as elegant, > particularly when I want to use an increasing value i within the loop. > Here's an example (with my limited ruby) > > i=0 > 0.upto(3) do puts 'try > number ' + i.to_s i = > i+1 # is there a more elegant way to > do i++ ? > end Try: 0.upto(3) do |i| puts "try number #{i}" end > I am guessing that ruby provides a more elegant way to do the above. I > would love recommendations both on how to iterate when I want to use the > changing value of the iterator in the loop, and how in ruby to do i++. i+=1 is the easiest way to increment a number. By the way: In many/most cases, you can iterate over a collection (e.g. an array) without worrying about the index, using #each. If you want to iterate over the same collection and you need the index, you can use each_with_index. HTH, Hal