Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel-eecis!gatech!csulb.edu!hammer.uoregon.edu!news-peer.gsl.net!news.gsl.net!newspump.sol.net!news.mindspring.com!mindspring!uunet!in2.uu.net!fox.almaden.ibm.com!garlic.com!news.scruz.net!cruzio.com!news
From: "James A. Sawyer" <jas@cruzio.com>
Subject: Re: about do loop
Content-Type: text/plain; charset=iso-8859-1
Sender: news@cruzio.com (System Administrator)
Content-Transfer-Encoding: quoted-printable
Organization: Cruzio Community Networking System, Santa Cruz, CA
Message-ID: <327A3440.56CD@cruzio.com>
References: <326FFC81mu00001@ibm.net> <Dzto71.C0q@heeg.de>
X-Mailer: Mozilla 2.0 (Win16; U)
Mime-Version: 1.0
Cc: jas@cruzio.com
X-Nntp-Posting-Host: kelp132.cruzio.com
Date: Fri, 1 Nov 1996 17:32:48 GMT
Lines: 71

> namik (mu00001@ibm.net) wrote:
> =

> Hi;
> =

> We have a question. Assume that we have an ordered collection (its size i=
s 100)
> and we are using do loop.  The question is how can I break the  do loop w=
hen its index
> is 33 without using "^"and we don=92t want to write code in the ifTrue bl=
ock.

It would be helpful to know what problem you are trying to solve, i.e. what=
 is it =

about certain members of the collection that interests you?  My suspicion i=
s that
you are solving the wrong problem, because you are using a view brought wit=
h you
from another language.

Generally speaking, when dealing with a collection, you do not want to use =
a 'do loop'.
You want to think in terms of the collection, not the indices.

Do you want to find a particular member?  =


    If so, use detect, as in

        particularMember:=3DmyOrderedCollection detect: [:member| member me=
etsSomeCondition].

Do you want to do something to/with some sub-grouping of members?  =

	=

    If so, use do, but as in

        myOrderedCollection do: =

                [:member| member meetsSomeCondition =

                        ifTrue: [someOtherObject doSomethingTo: member]
                ].

Do you need to manipulate the sub-group in several ways, once you've found =
it?

    If so, use collect, as in

	subGroup:=3DmyOrderedCollection collect: [:member| member meetsSomeConditi=
on].

	responsibleObject doSomethingWith: subGroup. =

	subGroup doSomethingToSelf.
	=

If you really want to iterate over the collection, in order, and stop when =
you hit =

a particular member, you're not really interested in the collection.  Back =
up, take
a new look at the problem, and do some more design...

regards,

-jim

