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!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: A few questions Date: Thu, 12 Nov 2015 20:19:47 +0000 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="29a2b57997615acde1fccc73c72adb9b"; logging-data="2606"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nGO6P8iVsz+Vg80BJ17KvzxfLJ2FSufk=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin) Cancel-Lock: sha1:DWec1pPSBpDAtVmdY3E55wlweZ4= sha1:F7BA3oxdRyQTarVaQCJhsJ8o020= Xref: news.eternal-september.org comp.lang.ada:28336 Date: 2015-11-12T20:19:47+00:00 List-Id: "Randy Brukardt" writes: > wrote in message > news:aa0cf839-651e-494d-a826-c2ce31a7afd3@googlegroups.com... >>> The "of" form is for iterating over an array or a container whose >>> type has the Default_Iterator aspect (which gives the iterator to >>> use). >> >> The main drawback, though, is that you then get a Cursor, not an >> Element, so you still need to call the functions Element or Reference >> to get to the actual element. This is slightly less convenient >> (syntax-wise). > > Sure, but not in a case like the OP's, where the "cursor" is the > actual data and there is no element. In that case, "of" is just > overkill. There's one problem for Times; how to determine when to end the loop if the cursor is the actual data? I ended up with type Cursor (Valid : Boolean := True) is record case Valid is when True => Date : Ada.Calendar.Time; when False => null; end case; end record; where both First and Next set Valid to False if the iteration has ended. I spent a lot too much time without giving Valid a default value; there is an assignment, but it's hidden inside the generated code, so at the end of the loop the discriminant changes ... I think this may be related to the way that F552A00_Prime_Numbers doesn't support an upper bound of 2; the loop terminates when Is_Prime returns false, and of course 2 + 1 = 3 which .. Is_Prime.