From: Robert Klemme Date: 2008-05-05T17:49:09+09:00 Subject: Re: Different Ways To Loop 2008/5/4 Wyatt Greene : > 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... I haven't seen 'retry' so far: 10:48:13 RTEConnector$ ruby -e 'i=0;begin;puts i;raise "X";rescue;i+=1;retry if i<=10;end' 0 1 2 3 4 5 6 7 8 9 10 10:48:25 RTEConnector$ Cheers robert -- use.inject do |as, often| as.you_can - without end