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 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ec4cde5d799065b6 X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Is there an ADA analogue to the C++ continue statement? Date: 1997/09/19 Message-ID: #1/1 X-Deja-AN: 273861997 References: <01bcc32e$350b5ba0$6409868b@gateway> <5vqm61$fu2$1@cf01.edf.fr> Organization: New York University Newsgroups: comp.lang.ada Date: 1997-09-19T00:00:00+00:00 List-Id: Heath, Terry D. ask about an Ada equivalent for : > while (condition-1) > { > statement-1; > > if (condition-2) > continue; > > statement-3; > } The most reasonable translation is to introduce a very stylized use of the goto for this purpose, putting a label <> just before the end loop, and then doing a goto to get the effect you want. So we would have: while Condition_1 loop statement_1; if Condition_2 then goto Continue; end if; statement_3; <> end loop; Now for some odd reason, many programmers have picked up allergies to gotos that are spelled using the goto keyword, though these same programmers do not mind gotos spelled with other keywords such as continue (the continue, since it can rip you out of deeply nested structures, is of course a form of goto, it just doesn't look like a goto, but it quacks like one :-) Yes, yes, we all understand that general inappropriate use of gotos is a BAD THING. For me that is just a special rule that general inappropriate use of *any* feature in a language is a bad thing. I don't stop myself using case statements in my programs just because some idiots misuse them, and equally I have no problem using goto in a stylized way as shown above just becausee some idiots misuse them. Whether the continue is sufficiently important to include as a fundamental gizmo is a continuing (ha ha) discussion in language design. Algol-60 did not have this construct, and the algol family generally followed this lead. Pascal for instance has no goto, and the one place you will find goto used in Wirth's book on algorithms is precisely for the continue construct given above (actually that's not quite true, there is another place where he uses it for a break out on an exceptional condition, but one would be more likely to use an exception for this purpose in Ada. Yes, it is possible to use a Boolean flag instead, but the fiddling around to do this can be a bit tortured if we contrive a deeply nested case. Final note: for Ada programmers who are incurably goto-challenged, you can achieve exactly the same effect as the above loop by using: while Condition_1 loop begin //// ooops let's try that again while Condition_1 loop declare Continue : exception; begin statement_1; if Condition_2 then raise Continue; end if; statement_3; exception when Continue => null; end loop; A kind compiler will translate this use of exceptions into a simple goto and bypass the normal exception mechanism. Why anyone would go to such circumlocutions escapes me, but some programmers will do almost anything to avoid the goto keyword, and besides there are silly coding standards around which totally forbid the use of the goto keyword. Why silly? Well to me, most absolute rules are a mistake, since there are almost always exceptions. Note that I avoid the mistake of phrasing this particular rule in absolute terms :-) Robert