From: Eric Mahurin Date: 2005-10-31T09:34:51+09:00 Subject: Re: Very useful... 'break' accepts an argument ------=_Part_13706_2851730.1130718888581 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 10/30/05, Joel VanderWerf wrote: > > Tom Agnew wrote: > > Greetings, > > > > I just discovered undocumented but very useful syntax: > > > > break > > > > The expression seems to add a useful feature to a 'while', 'until' or > > 'for' control structure. For example: > > > > result =3D while > > ... > > break > > ... > > end > > > > 'result' is nil if the loop exits with and is i= f > > the break is executed. > > > > Very useful and provides an cool addition to an already elegant > > collection of iterator constructs! > > > > Tom Agnew3 > > > > It's also cool because it works with your own iterators (really, any > method that takes a block), not just ruby syntax like while. > > def foo > yield > end > > x =3D foo do > break 4 > end > > p x > Unfortunately the base iterators return the object they are iterating over instead of nil like the non-iterator loops (while, until, loop). For the non-iterator loops nil can mean terminate normally if you use break with a value (non-nil). For iterator loops you have to do the opposite - break wit= h a value is of little use. I discussed the problem here: http://rcrchive.net/rcr/show/305 ------=_Part_13706_2851730.1130718888581--