Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!uwm.edu!spool.mu.edu!munnari.oz.au!goanna!minyos.xx.rmit.oz.au!fmarh From: fmarh@minyos.xx.rmit.oz.au (Robert Hinterding) Newsgroups: comp.lang.smalltalk Subject: Re: Nested Control Structures Within Iterators Message-ID: <1991Apr8.234951.22900@minyos.xx.rmit.oz.au> Date: 8 Apr 91 23:49:51 GMT References: <41040@cup.portal.com> Organization: Victoria University of Technology, Melbourne Australia. Lines: 42 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? > >Thanks, >Will Estes Internet: Will@cup.portal.com > UUCP: apple!cup.portal.com!Will The problem is that do: is for iterating over the whole collection. To do what you want, you need to use a different method. As you stated that input was a file stream a way of doing it is shown below. [ condition and:[ input atEnd not] ] whileTrue:[ input next "more code here" ] whileTrue is a method for class Context, atEnt and next are methods for class FileStream in the example. I hope this helps you. -- Robert Hinterding fmarh@minyos.xx.rmit.oz.au Victoria University of Technology Phone +61 3 6884686 PO Box 64, Footscray 3011 Fax: +61 3 687 7632 Australia