From: Brian Candler Date: 2003-07-09T18:29:37+09:00 Subject: Re: Possible use for a continuation? [Generating all factors of a given number] On Wed, Jul 09, 2003 at 05:40:40PM +0900, Harry Ohlsen wrote: > which can be called like ... > > isGenerator = true > > Primes.each_factor(phi) do |factor| > exponent = phi / factor > > if (i ** exponent).to_i == 1 > isGenerator = false > end > > isGenerator > end > > The only problem with this is that you can't really "return" a value from > a block (or, at least, I don't believe so), which makes the last line, > which has to "return" true or false, so that the iterator knows whether to > continue, isn't quite as obvious as I'd like. IIRC, 1.8 has "next " and "break " which return a value. In the above case, if 'isGenerator = false' terminates the loop, you could just write exponent = phi / factor (i ** exponent).to_i != 1 # continue condition Regards, Brian.