Lukas Renggli a écrit :
My preferred way is the following:

Add the following method to Object (or somewhere else):

Object>>escaper: aBlock
   ^ aBlock value: [ ^ nil ]

Then implement your loop like this:

self escaper: [ :break |
   1 to: 10 do: [ :x |
      x = 3 ifTrue: [ break value ].
      ... ] ]

Cheers,
Lukas


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



_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to