From: Tim Hunter Date: 2008-03-03T23:30:47+09:00 Subject: Re: Normal For Loop Jano Svitok wrote: > On Mon, Mar 3, 2008 at 3:10 PM, Cory Cory wrote: >> I'm new to Ruby. Is there such thing as a C++ style (and most others) >> for loop in Ruby? What I mean by that is: >> >> for( init, while-condition, increment ) { function-here } >> >> I know I can do that with a while loop, but I enjoy the compactness of >> the above statement. There are many times where Ruby's for-each loops >> just don't do the trick. > > There is 5.times {|i| } if the count is known at cycle start. > Then you have array.each {}, and the whole bunch from Enumerable > (each_with_index, select, find, map, inject, ...) Not to mention Numeric#step: 1.step(10, 2) { |i| print i, " " } And Integer#upto: 5.upto(10) { |i| print i, " " } -- Posted via http://www.ruby-forum.com/.