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.szaf.org!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: Thu, 04 Jan 2018 22:52:43 +0100 Message-ID: <867esx70lw.fsf@gaheris.avalon.lan> References: <81971548-23c9-4927-a6a8-6f0f1dba896b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain X-Trace: individual.net rByjdOafXfZXRUxHkvkMaA8/Es+icqAISALYKwmw5Bv64pNdC1 X-Orig-Path: gaheris.avalon.lan!not-for-mail Cancel-Lock: sha1:lajj+0ilIz+NThmrzg2hxMEDOaY= sha1:TiHAaNNyE/JE3T3+A7Ibfrj8M5I= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Xref: reader02.eternal-september.org comp.lang.ada:49757 Date: 2018-01-04T22:52:43+01:00 List-Id: "Jeffrey R. Carter" writes: > On 01/04/2018 12:17 AM, Robert A Duff wrote: >> >> Jeff's suggestion (nested 'if' in the loop) is a good one when it works, >> but it doesn't work when the "continue" is nested within further control >> constructs. > > 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 (a popular one is in file processing, to skip comment lines: next if /^#/; aka, skip this line if it starts with a # character indicating a comment) Since these are basically guard clauses, the idiom is clear to anyone with more than a cursory knowledge of the language (and anyone pretending to be a programmer, let alone a software engineer, should be smart enough to recognise this as the loop equivalent of a guard clause on a second look). The resistance against adding a similar construct to Ada is puzzling to me. It is clear, and more elegant than the more general 'goto' that is the only way to do this in Ada. Adding a goto with a label at the top of the loop is not clear until you seek out the label near the 'end loop' statement; if that is out of sight it may well appear as an attempt to break out of the loop. Mart -- "We will need a longer wall when the revolution comes." --- AJS, quoting an uncertain source.