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,FREEMAIL_FROM, INVALID_MSGID 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: "Chad R. Meiners" Subject: Re: checking a loop execution Date: 2000/04/22 Message-ID: <3901fc68.0@silver.truman.edu>#1/1 X-Deja-AN: 614488778 References: <8dl76u$etf$1@nnrp1.deja.com> <38fece05.0@silver.truman.edu> <8do7b2$p8h$1@nnrp1.deja.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Trace: news.more.net 956453972 150.243.160.9 (Sat, 22 Apr 2000 20:39:32 CDT) X-MSMail-Priority: Normal NNTP-Posting-Date: Sat, 22 Apr 2000 20:39:32 CDT Newsgroups: comp.lang.ada Date: 2000-04-22T00:00:00+00:00 List-Id: "Robert Dewar" wrote in message news:8do7b2$p8h$1@nnrp1.deja.com... > 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. hmm... Would you care to explain how this variable is annoyingly obfuscating, or do you prefer to make unsupported assertions ;) I did consider using gotos, but I didn't think that this problem warranted them. > 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. My first programming language was BASIC. So please do not assume that I dislike gotos in fact I actually agree with you that the above rule is silly and that style rules are guidelines. Perhaps you should have politely asked why I decided not to use gotos. It would have been more constructive and better received. (Remember this isn't necessary my advice it could have been your mother's) > 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. Yes provided that the loop is short and uncomplicated (which in this case it is ;). However, the use of a for loop sets up the expectation that the loop is going to execute a predetermined amount of times. Therefore putting other exit conditions inside of a for loop is misleading to the reader. A while loop also carries similar expectations, but a general loop construct does set up such expectations, and thus the reader expects that they are going to be defined inside the loop. This is why my code is constructed as it is. I wanted the exit conditions to be precisely and clearly defined. Since both the for and while loop carried unwanted expectation I didn't use them. Now I guess I should explain why I used and exit when and an if block instead of the gotos that Dr. Dewar seems so fond of advocating. First, exits are what you normally use to exit out of a loop. Second, gotos tend to set off warning bells when a reader encounters them, and I didn't feel that the code was doing anything that deserved to alarm the reader. Third, I figured that the compiler would remove the additional check since Interrupted remains constant after the loop has been exited. > > 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 :-) Although I am not familiar with COBOL's syntax, if STOP RUN is an something like BREAK or STOP then it makes perfect sense to use it instead of a goto THE_END equivalent, since label names don't have to tell the truth. ( I know the joke is that the programmer didn't believe the two were equivalent ;) > Sometimes I have seen goto allergic people do this in Ada > too, interfacing the exit routine! Find it amusing that you attach these jokes in reply to my posting given that they bear no relevance what so ever since I am clearly not allergic to gotos. So clearly there is no reason to go on a crusade.