From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_05,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!VMA.CC.CMU.EDU!madmats%elcgl.epfl.ch From: madmats%elcgl.epfl.ch@VMA.CC.CMU.EDU (Mats Weber) Newsgroups: comp.lang.ada Subject: On quitting an iterator prematurely Message-ID: <900411123821.24207ca9@SIC.Epfl.CH> Date: 11 Apr 90 11:38:21 GMT Sender: usenet@ucbvax.BERKELEY.EDU Organization: The Internet List-Id: >When I was to use the package I discovered one thing I had missed. >There was no way to interrupt the iteration. One way is of course >to rewrite the package so that Process_one_element should take a >second parameter > Continue : OUT boolean; Personally, I prefer to use exceptions in this case, because it is really an EXCEPTIONal case. But if the additonal boolean parameter is to be used, then it can be better to make it 'in out' instead of 'out' so that if the action procedure does not modify the parameter (or the programmer forgets to set it, which leads to erroneous programs), iteration continues by default. example: generic with procedure Action(X : in Item; Quit : in out Boolean); procedure Iterate is Do_Quit : Boolean := False; begin loop ... Action(X, Do_Quit); exit when Do_Quit; end loop; end; Mats Weber Swiss Federal Institute of Technology EPFL DI LGL 1015 Lausanne Switzerland E-mail : madmats@elcgl.epfl.ch phone : +41 21 693 52 92 fax : +41 21 693 39 09