nicolas cellier <ncellier <at> ifrance.com> writes:
>
> Very Smaltalk-ish!
>
> Even works if you want to escape nested loop:
>
> self escaper: [:breakOuter |
> 1 to: 10 do: [:i |
> self escaper: [:breakInner |
> 1 to: 10 do: [:j |
> j = 3 ifTrue: [breakInner value].
> (j = 2 and: [i = 7]) ifTrue: [breakOuter value]]]]].
>
> Nicolas
>
Thank you for your answers, I also found a solution by extending the Number
class like this:
Number extend [
to: stop do: aBlock butPleaseExitIf: aCondition [
<category: 'shortcuts and iterators'>
| i |
i := self.
[(i <= stop) and: [(aCondition value: i) not]] whileTrue:
[aBlock value: i.
i := i + self unity]
]
]
This to:do:butPleaseExitIf: selector allows you to use expressions like:
1 to: 10 do: [:x | x printNl.] butPleaseExitIf: [:x | x = 3.]
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk