Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.kei.com!newsfeed.internetmci.com!uwm.edu!spool.mu.edu!torn!nott!cunews!tina.mrco.carleton.ca!knight
From: knight@mrco.carleton.ca (Alan Knight)
Subject: Re: Why use Smalltalk as the primary development language ...
X-Nntp-Posting-Host: tina.mrco.carleton.ca
Message-ID: <knight.820097004@tina.mrco.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Reply-To: knight@acm.org (Alan Knight)
Organization: The Object People
References: <DK6DM4.8As@cunews.carleton.ca> <4bs6r4$dvt@rznews.rrze.uni-erlangen.de>
Date: Wed, 27 Dec 1995 20:43:24 GMT
Lines: 33

In <4bs6r4$dvt@rznews.rrze.uni-erlangen.de> Bruno.Bienfait@EROS.CCC.uni-erlangen.de (Bruno Bienfait) writes:
>But something useful is still missing : loop control statements like break  
>and continue in C or, next, redo and last (with and without label) in  
>Perl. 

>I would like to write something like :
> 1 to: 1000 do: [:i | i printString; cr.
>(anArray at: i) == 0 ifTrue: [thisLoop break] ]

It sounds like you want something like

  (1 to: 1000) detect: [:i | i
    Transcript show: i printString;cr.
    (anArray at: i) = 0].

although this is a pretty contrived statement. If you were trying to
accomplish something real, instead of just printing numbers to the
transcript, it could be done more simply in a lot of cases vai anArray
detect:...

Although Smalltalk doesn't have a loop break statement, it has method
return statements, which can be used to simulate it pretty easily
under most cases (q.v. detect:). The worst you have to do is break
your code up into two separate methods, which is often a good thing
anyway.


	-- 
 Alan Knight                | The Object People
 knight@acm.org             | Smalltalk and OO Training and Consulting
 alan@objectpeople.on.ca    | 509-885 Meadowlands Dr.
 +1 613 225 8812            | Ottawa, Canada, K2C 3N2

