Path: sran265!katsu From: katsu@sra.co.jp (WATANABE Katsuhiro) Message-ID: Date: 22 Feb 1994 09:31:53 GMT Organization: Software Research Associates, Inc.,Japan In-reply-to: iwm@doc.ic.ac.uk's message of 11 Feb 1994 20:23:39 GMT Newsgroups: comp.lang.smalltalk Subject: Re: leaving a block ? Distribution: world References: In article iwm@doc.ic.ac.uk (Ian Moor) writes: > Is it possible to leave a block without leaving the surrounding method ? > for example in using do: > > s do: [ :element | (element isMemberOf: Thing) ifTrue: [ found := true. ..? ]] > " More code to be done" As have been shown already, using detect: or adding special method into BlockClosure will solve the problem. But, let me propose yet another way, which can be applicable on PPS Smalltalk only: | signal result | signal := Object informationSignal newSignal. result := signal handle: [:ex | ex returnWith: ex parameter] do: [ s do: [:element | (element isMemberOf: Thing) ifTrue: [signal raiseWith: element]]. nil]. "check if the result is nil or not" I'd say it's rather flexible because you can exit a block (to say, raise the signal) even from deep inner method which you called from the block. -- WATANABE Katsuhiro Software Research Associates, Inc. (Tokyo JAPAN)