comp.lang.ada
 help / color / mirror / Atom feed
From: madmats%elcgl.epfl.ch@VMA.CC.CMU.EDU (Mats Weber)
Subject: On quitting an iterator prematurely
Date: 11 Apr 90 11:38:21 GMT	[thread overview]
Message-ID: <900411123821.24207ca9@SIC.Epfl.CH> (raw)


>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

             reply	other threads:[~1990-04-11 11:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-04-11 11:38 Mats Weber [this message]
     [not found] <9004262133.AA06607@hac2arpa.hac.com>
     [not found] ` <7050@fy.sei.cmu.edu>
1990-05-01 16:09   ` On quitting an Iterator Prematurely Mike Feldman
     [not found] <9004041704.AA17624@ajpo.sei.cmu.edu>
1990-04-08 12:07 ` On quitting an iterator prematurely Erland Sommarskog
1990-04-10 18:26   ` Sylvain Louboutin, University College Dublin, Ireland
1990-04-11  2:05   ` tdhammer
1990-04-13 22:04     ` David Kassover
1990-04-13 22:50       ` Mike Feldman
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox