> -----Original Message----- > From: marnen / marnen.org [mailto:marnen / marnen.org] > >> Now consider the ruby way: > >> > >> 10.times do |i| > >> print "#{i}," > >> end > >> > >> Some length as the C code, but much more readable. Heck, it's > >> almost English! > > > > Well, you do have to know what Numeric#times yields to its block. But > that's easy to look up. (However, it starts from 0, so it's not quite > equivalent to the C.) Whoop! Good point, that's what I get for not actually testing my code. Corrected (and even closer to English). (1..9).each do |i| print "#{i}," end Michael Wrote: > > Not for me it wasn't. I had to try it to see that it actually works. > > My initial impression was that it would print 10 copies of i. > I still don't see where 'i' is incremented It isn't incremented, at least not in MY code (if you must think in terms of incrementing variables, then Ruby is incrementing it for me) See the times method at: http://ruby-doc.org/core/classes/Integer.html That kind of looping is a pretty core Ruby concept. Also the corrected version I wrote above should be a bit clearer. Also I think your previous programming experience is hurting you here. To you as (I'm guessing) a C programmer, to progress in a loop, you must increment modify variable. The average English speaker doesn't think in those terms. Looking at my most recent example, the English equivalent would be for each 'i' from 1 to 9 print 'i' followed by a comma. Sure, the words may not be in the precise order, but it comes a darn site closer to natural language than: int i=1; while (i<10) { printf("%d,",i++); }