From: daz Date: 2003-07-09T15:08:41+09:00 Subject: Re: Possible use for a continuation? [Generating all factors of a given number] "Harry Ohlsen" wrote: > [...] since in many cases, I'll decide after having > processed one of them that I don't need any more. > > I'm open to any suggestions, whatsoever. > Glad you said that ;) Continuations might be more-than-required since you suggest that when a condition arises, the game is up. catch / throw may be what you need. N.B. I haven't done the job but just to show that throw can be issued from anywhere ... def gen_value_single(n, r) ret_ = [] 0.upto(r) do |i| ret_ << n ** i throw :enough if ((false)) end ret_ end def gen_values(arr) all_done = false catch :enough do arr.each do |n, r| p gen_value_single(n, r) # ### accumulate stuff # throw :enough if ((false)) end all_done = true end # post-catch return all_done end gen_values( [[2,3], [3,2], [5,2], [7,1]] ) And, because I don't know your condition, I've entered false. The (useless) output from above is: [1, 2, 4, 8] [1, 3, 9] [1, 5, 25] [1, 7] daz