comp.lang.ada
 help / color / mirror / Atom feed
* On quitting an iterator prematurely
@ 1990-04-11 11:38 Mats Weber
  0 siblings, 0 replies; 8+ messages in thread
From: Mats Weber @ 1990-04-11 11:38 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 8+ messages in thread
[parent not found: <9004041704.AA17624@ajpo.sei.cmu.edu>]

end of thread, other threads:[~1990-05-02 20:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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
1990-05-02 20:24     ` First as Successor to Last (was On quitting an Iterator Prematurely) Karl A. Nyberg
1990-04-11 11:38 On quitting an iterator prematurely Mats Weber
     [not found] <9004041704.AA17624@ajpo.sei.cmu.edu>
1990-04-08 12:07 ` 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

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