Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!haven.umd.edu!news.umbc.edu!eff!news.duke.edu!news.mathworks.com!news.kei.com!nntp.coast.net!frankensun.altair.com!sdd.hp.com!hp-pcd!hp-cv!reuter.cse.ogi.edu!qiclab.scn.rain.com!slc.com!servio!servio!aland
From: aland@servio.slc.com (Alan Darlington)
Subject: Re: Why use Smalltalk as the primary development language ...
Message-ID: <1995Dec28.024627.11042@slc.com>
Sender: news@slc.com (USENET News)
Nntp-Posting-Host: servio
Organization: GemStone Systems, Inc., Beaverton OR, USA
References: <DK6DM4.8As@cunews.carleton.ca> <4bs6r4$dvt@rznews.rrze.uni-erlangen.de>
Date: Thu, 28 Dec 1995 02:46:27 GMT
Lines: 45

Bruno.Bienfait@EROS.CCC.uni-erlangen.de (Bruno Bienfait) writes:
<snip of loop constructs> 
> 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] ]
<snip>

The "break" may be replaced by a return if you are willing to put
part of the code in a separate method - for example:

  indexOfFirstZeroIn: anArray

    1 to: anArray size do:
      [: index |
      0 == (anArray at: index) ifTrue:
        [^ index]].
    ^ nil


Obviously this does not work with in-line code, but it does
help in breaking a large method into smaller ones, which I
personally consider to be a good practice in any case.

Also, you could easily add new loop methods that would handle
the extensions you wish.  For example:

  index := 1 to: anArray size doWithBreak:
    [: index : breakBlock |
    0 == (anArray at: index) ifTrue:
      [breakBlock value: index]].

(This is just off the top of my head - you can fill in the
details yourself.  The other functions do not seem to be
any more difficult technically, but your mileage may vary.
I have not actually tried to implement this!)

  Cheers,
  Alan
    (standard disclaimer)


