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=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f6a85e71d2c330ab X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: checking a loop execution Date: 2000/04/21 Message-ID: <8do7b2$p8h$1@nnrp1.deja.com>#1/1 X-Deja-AN: 613743842 References: <8dl76u$etf$1@nnrp1.deja.com> <38fece05.0@silver.truman.edu> X-Http-Proxy: 1.0 x21.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Fri Apr 21 00:28:33 2000 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; I) Date: 2000-04-21T00:00:00+00:00 List-Id: In article <38fece05.0@silver.truman.edu>, "chad" wrote: > The following code does what you want: > > declare > Index : Integer := 1; > Interupted : Boolean := False; > begin > > loop > > Interupted := ; I find the use of boolean variables like this annoying obfuscation in many cases. I would not mind at all using a goto for this special case of a loop with multiple exits. Some languages have a special construct for this, but if this is lacking, then really the goto is as clear as anything and avoids duplicating a test. Yes, I know some people get the heebie-jeebies when they see a goto, but just remember you weren't born this way, it is learned behavior, and it can be unlearned. Almost every style rule should be considered as a guide, and the really skilled programmer is one who does not have to rely on absolute rules like "Never use a goto", and instead knows enough to discriminate. Code like for J in 1.. 10 loop if Condition then goto Loop_Interrupted; .... end loop; -- Here if loop ends normally ... return; -- Here if loop ends abnormally <> ... return; reads quite clearly to me, and I would be surprised and a bit puzzled by any programmer to whom it did NOT read clearly. And as someone pointed out, if the interrupted section is short, you can simply put it right in the loop (of course a return from the middle of a scope is also a goto, but often an acceptable one -- the amusing thing is people who hate *all* gotos, but don't recognize that statements like return are gotos :-) I think I mentioned before running into a COBOL programmer who hated gotos but had no hesitation in writing a STOP RUN verb deeply embedded into his program :-) Sometimes I have seen goto allergic people do this in Ada too, interfacing the exit routine! Sent via Deja.com http://www.deja.com/ Before you buy.