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 X-Received: by 10.107.16.206 with SMTP id 75mr10129547ioq.31.1474270630043; Mon, 19 Sep 2016 00:37:10 -0700 (PDT) X-Received: by 10.157.8.10 with SMTP id 10mr1544337oty.16.1474270630005; Mon, 19 Sep 2016 00:37:10 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!u18no1855739ita.0!news-out.google.com!b4ni5349iti.0!nntp.google.com!x192no1987239itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 19 Sep 2016 00:37:09 -0700 (PDT) In-Reply-To: <23ee42b9-8145-4d15-a745-a264505be8ff@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.218.37.33; posting-account=W2gdXQoAAADxIuhBWhPFjUps3wUp4RhQ NNTP-Posting-Host: 76.218.37.33 References: <23ee42b9-8145-4d15-a745-a264505be8ff@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5113a69b-9b18-4a2f-999d-d32db69e3681@googlegroups.com> Subject: Re: "for E of Vector1 loop" equivalent to "for n in Vector1.First_Index .. Vector1.Last_Index loop ? From: Stephen Leake Injection-Date: Mon, 19 Sep 2016 07:37:10 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:31818 Date: 2016-09-19T00:37:09-07:00 List-Id: On Monday, September 19, 2016 at 2:23:10 AM UTC-5, reinkor wrote: > Assume Vector1 is a vector (container) and I want to loop through it in the direction Vector1.First_Index .. Vector1.Last_Index. > > Is the following equivalent: > > for n in Vector1.First_Index .. Vector1-Last_Index loop > > end loop; > > and > > for E of Vector1 loop > > end loop; Yes > It is for me not directly intuitive that the latter construct > process the vector elements in the same order as the former. > I feel I should find the answer in the definition of Ada - but din not :-) See LRM 5.5.2 10: For a generalized iterator, the loop parameter is created, the iterator_name is evaluated, and the denoted iterator object becomes the loop iterator. In a forward generalized iterator, the operation First of the iterator type is called on the loop iterator, to produce the initial value for the loop parameter. If the result of calling Has_Element on the initial value is False, then the execution of the loop_statement is complete. Otherwise, the sequence_of_statements is executed and then the Next operation of the iterator type is called with the loop iterator and the current value of the loop parameter to produce the next value to be assigned to the loop parameter. This repeats until the result of calling Has_Element on the loop parameter is False, or the loop is left as a consequence of a transfer of control. For a reverse generalized iterator, the operations Last and Previous are called rather than First and Next.