From: David Alan Black Date: 2001-11-14T07:35:07+09:00 Subject: [ruby-talk:25095] Re: exiting blox On Wed, 14 Nov 2001, Alan Chen wrote: > On Wed, Nov 14, 2001 at 07:19:05AM +0900, David Alan Black wrote: > > Hello -- > > > > On Wed, 14 Nov 2001, Niko Schwarz wrote: > > > > > Hi there, > > > is there a way to exit a block before time? > > > like: > > > > > > field.each { |el| > > > if(el.alsacian?) > > > break #no, dont want anymore > > > else > > > puts el > > > end > > > } > > > > > > is there? (note: i want to exit it just for one el, of course) > > > > Doesn't break do what you want? Or am I confused about what > > it does? > > break also stops any subsequent yields to the block. I think Niko > just wants to skip the rest of the block for that yield. Ah, that's a job for "next": [1,2,3,4].each { |e| puts "Looking at #{e}..." if e == 3 next else puts "#{e} isn't 3!" end } David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav