From: Wyatt Greene Date: 2008-05-05T05:30:03+09:00 Subject: Re: Different Ways To Loop On May 4, 3:22 pm, Ken Bloom wrote: > On Sat, 03 May 2008 19:07:12 -0700, Wyatt Greene wrote: > > I love the flexibility of Ruby. It gives you several ways to do > > something, leaving you to pick the most appropriate one. In the spirit > > of showing off the flexibility of Ruby, I'd like to see how many > > different ways there are to write a loop that prints the numbers 1 to > > 100, one on each line. I'll start off: > > > 1.upto(100) { |x| puts x } > > > I know there's at least a dozen more ways to do this... > > ([nil]*100).each_with_index{|_,i| puts i+1} > Array.new(100).each_with_index{|_,i| puts i+1} > > -- > Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. > Department of Computer Science. Illinois Institute of Technology.http://www.iit.edu/~kbloom1/ Nice ones, Ken! :) Here's another one, lifted from page 128 of "The Ruby Programming Language": x = 10 puts x = x + 1 while x < 100