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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: stopping a loop iteration without exiting it Date: Fri, 5 Jan 2018 15:05:13 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <81971548-23c9-4927-a6a8-6f0f1dba896b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 5 Jan 2018 14:05:14 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="f5d98908cdce36eccd1e824541905cc9"; logging-data="12153"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+u1VBXt8V+ijC+0lqITCNDDsJO6hb0qG8=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:ErC3wcSLCQKvOB1aoHwXUNC+PRs= Xref: reader02.eternal-september.org comp.lang.ada:49766 Date: 2018-01-05T15:05:13+01:00 List-Id: On 01/05/2018 02:17 AM, Randy Brukardt wrote: > > There are a number of instances of it in the spam filter. When it is > determined that a particular pattern cannot possibly match, one does a > "continue" to move on to the next pattern. This is usually in an inner loop > (so this is acting as a combination exit and continue). The rules for the > spam filter turn out to be very complex, so the code implementing them also > end up complex; simplifying the rules leads to allowing spam through or > blocking "ham" (good mail). and also (in another post): > It's not a frequent need, it's just a non-zero need. I find I end up up > writing such a goto (very roughly) once a year. But a good number of them > aren't strict continues; there's often something at the bottom of the loop > after the label. I don't know of any language that has a "continue" that will apply to any but the innermost containing loop, so such languages would not seem to have any advantage in this case anyway. I suppose Ada could be the 1st with such a feature. I don't know of any language with a "continue-like" feature that includes executing some code at the end of the continued loop. I can't imagine what such a feature might even look like. But it appears that even if Ada had a "continue" feature, it might not replace the goto of many of your real-world examples. I've never written a spam filter, but I'd imagine that one would be structured something like All_Msgs : loop exit All_Msgs when Msg_Source.Is_Empty; Msg := Msg_Source.Get; Is_Spam := False; All_Patterns : for Pattern of Patterns loop Is_Spam := Pattern.Check (Msg); if Is_Spam then Reject (Message => Msg); exit All_Patterns; end if; end loop All_Patterns; if not Is_Spam then Allow (Message => Msg); end if; end loop All_Msgs; and moving on to the next pattern would be "return False;" in Check. Reality is probably more complex than this. -- Jeff Carter "Brave Sir Robin ran away." Monty Python and the Holy Grail 59