Newsgroups: comp.lang.misc Path: utzoo!utgpu!jarvis.csri.toronto.edu!turing.toronto.edu!erlebach From: erlebach@turing.toronto.edu (Beverly Erlebacher) Subject: Re: Loops Message-ID: <8804020507.AA07313@turing.toronto.edu> References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> Date: Fri, 1 Apr 88 22:07:42 EST <294@tmsoft.UUCP> <2797@mmintl.UUCP> Reply-To: erlebach@turing.UUCP (Beverly Erlebacher) Organization: University of Toronto, CSRI >In article <294@tmsoft.UUCP> mason@tmsoft.UUCP (Dave Mason) writes >>>The more I program, the more convinced I become that the 'while' loop is a >>>mistake. It just doesn't match the semantics of too many real loops. >>>(1) Exit from any point in the loop. >>>(2) Multiple exits. >>>(3) Code can be associated with any exit point. > >I want to re-emphasize point (3) here. In a structured program, there >should be a (relatively) simple statement of the state of the computation >when you exit from the loop. When there are multiple bare exit points, it >is likely that the simplicity of that condition must be sacrificed. This > > for i = 1 to n; > ... > while P(i); > ... > end; > > if i > n /* Check for normal exit from loop */ > ... >or even worse kludges. (I want to emphasize that this is a practical >objection as well as a theoretical one.) >The examples Dave gives are all missing this facility. >Add optional exit code for each for and while, and you've got my approval. Dave's example doesn't include one of the features Frank is looking for. In addition to loop ... exit when condition ... end loop Turing has an even more general loop exit: loop ... if condition then ... exit ... end loop This allows statements to be conveniently associated with any of several exits. The Turing for loop also allows both styles of exit statement. I hope this wins Frank's approval. :-) ----------------------------- B.A.Erlebacher erlebach@csri.toronto.edu