Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!portc01.blue.aol.com!news-peer.gsl.net!news.gsl.net!news.mathworks.com!fu-berlin.de!unlisys!blackbush.xlink.net!ins.net!heeg.de!hmm
From: hmm@heeg.de (Hans-Martin Mosner)
Subject: Re: about do loop
Message-ID: <Dzto71.C0q@heeg.de>
Sender: uucp@heeg.de
Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
X-Newsreader: TIN [version 1.2 PL2]
References: <326FFC81mu00001@ibm.net>
Date: Fri, 25 Oct 1996 08:13:48 GMT
Lines: 31

namik (mu00001@ibm.net) wrote:

: Hi;

: 	We have a question. Assume that we have an ordered collection (its size is 100)
: and we are using do loop.  The question is how can I break the  do loop when its index is 33 without using "^"and we dont want to write code in the ifTrue block. 

When you ask questions in this way you are essentially saying:
"Wash my fur, but don't make me wet!"
What's so bad about using the most natural and commonly used
solution to this problem?

First I wanted to refrain from providing a possible solution, but now
I think of one that is both compact and obscure:

Use the #detect:ifNone: method in this way:

	index := 0.
	aCollection
		detect: [:elem |
			self doSomethingWith: elem.
			(index := index+1) >= 33]
		ifNone: [].

Hans-Martin

--
+--- Hans-Martin Mosner ---- Senior Smalltalk Guru :-) ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+--- <hmm@heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+
