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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mart van de Wege Newsgroups: comp.lang.ada Subject: Re: stopping a loop iteration without exiting it Date: Fri, 05 Jan 2018 15:35:50 +0100 Message-ID: <86373k74qh.fsf@gaheris.avalon.lan> References: <81971548-23c9-4927-a6a8-6f0f1dba896b@googlegroups.com> <867esx70lw.fsf@gaheris.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain X-Trace: individual.net e9Xu3A9Xlbw1yb/klrZdewpBG0eQVUFl3UzZVPEhYmjitF7ocH X-Orig-Path: gaheris.avalon.lan!not-for-mail Cancel-Lock: sha1:jbIpWid3Z5r8QYP4a29CN3AIPjc= sha1:lhD123+21STYiSRUj5QGo/X7Kxc= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Xref: reader02.eternal-september.org comp.lang.ada:49767 Date: 2018-01-05T15:35:50+01:00 List-Id: "Jeffrey R. Carter" writes: > On 01/04/2018 10:52 PM, Mart van de Wege wrote: >> "Jeffrey R. Carter" writes: >>> >>> I have never seen a real-world situation in which a "continue" was >>> needed. >> >> It's a common idiom in Perl when looping over a stream of discrete items >> (like lines in a file). A test at the top of the loop for cases where >> processing is not necessary in the form of >> >> next if > > I hardly think Perl is a good example for Ada language design > decisions. That answer is a bit parochial. And you're moving the goalposts. No matter how messy Perl is as a language, it is being used in the real world, and the use case of processing a stream of discrete elements is not particularly rare. The idiom is in common use, even if it is not in a language to your liking, so your 'never seen a real-world situation' remark is simply not true. > This appears to be exactly an example that can be replaced > by an if statement, anyway. Creating an unnecessary extra block, making code less readable. And what of the situation where you want to test for more than one exceptional situation before handing over your input to the main body of the loop? You want nested ifs? In my opinion a 'continue' construct is a useful bit of syntactic sugar that makes adding guard clauses to a loop easy and obvious to the reader of the code. It is by no means *necessary*. A goto statement works just the same. (As an aside, could it not be implemented using Pre- and Post-Conditions, just as in subprograms?) Mart -- "We will need a longer wall when the revolution comes." --- AJS, quoting an uncertain source.