Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!mcnc!nowhere!rick From: rick@cua.cary.ibm.com (Rick DeNatale) Newsgroups: comp.lang.smalltalk Subject: Re: Nested Control Structures Within Iterators Message-ID: <1991Apr11.182401.10775@cua.cary.ibm.com> Date: 11 Apr 91 18:24:01 GMT References: <41040@cup.portal.com> <1991Apr8.234951.22900@minyos.xx.rmit.oz.au> Sender: rick@cua.cary.ibm.com.UUCP (Rick DeNatale) Reply-To: rick@cua.cary.ibm.com.UUCP (Rick DeNatale) Organization: CUA Lines: 41 >In article <41040@cup.portal.com> Will@cup.portal.com (Will E Estes) writes: >Can someone explain to me whether it is possible to place another >control structure on the same line as an iterator? Say, for instance, >that I'm iterating across a file stream and I want to continue to >do so only while some condition is true. > > input do: > [ > :char | > output nextPut: char. > "more code here" > ]. > >Now what I would like to do is qualify the iteration of do: such that >when some condition becomes true we stop iterating? One thought that >comes to mind is an equivalent to the C control structure BREAK, but >I was not able to find this. Is there someone of achieving the effect >of BREAK? And if not is there some way of further qualifying the >iterator statement? > One way to do this is: input detect: [ :char | output nextPut: char. conditional test ] ifNone: [ ] conditional test would be an expression which would evaluate to true if you want to terminate the loop. The ifNone: [ ], avoids an error if the end of input is reached before the test succeeds. The empty block could be replaced with something useful if you wanted to do something special if the whole input was processed. Rick DeNatale Of course my opinion is my own, who else would want it?