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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.237.51.196 with SMTP id v62mr3855743qtd.40.1474271426391; Mon, 19 Sep 2016 00:50:26 -0700 (PDT) X-Received: by 10.157.4.137 with SMTP id 9mr1549228otm.3.1474271426350; Mon, 19 Sep 2016 00:50:26 -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!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!w41no1161025qtw.1!news-out.google.com!w143ni5724itb.0!nntp.google.com!x192no1990941itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 19 Sep 2016 00:50:26 -0700 (PDT) In-Reply-To: <5113a69b-9b18-4a2f-999d-d32db69e3681@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.167.239.219; posting-account=bPTmZAoAAAC_6HP9XLKB9aAAxBa6BuOR NNTP-Posting-Host: 85.167.239.219 References: <23ee42b9-8145-4d15-a745-a264505be8ff@googlegroups.com> <5113a69b-9b18-4a2f-999d-d32db69e3681@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: "for E of Vector1 loop" equivalent to "for n in Vector1.First_Index .. Vector1.Last_Index loop ? From: reinkor Injection-Date: Mon, 19 Sep 2016 07:50:26 +0000 Content-Type: text/plain; charset=UTF-8 X-Received-Bytes: 3301 X-Received-Body-CRC: 1315245008 Xref: news.eternal-september.org comp.lang.ada:31819 Date: 2016-09-19T00:50:26-07:00 List-Id: On Monday, September 19, 2016 at 9:37:11 AM UTC+2, Stephen Leake wrote: > 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. Thanks. And a follow-up question: I like the construct for E of Vector1 loop .. end loop; but is there a possibility somehow to keep this style and execute opposite direction, equivalent to: for i in reverse Vector1.First_Index .. Vector1.Last_Index loop .... end loop ? reinert