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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,51bff7cd4c35a15d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.191.225 with SMTP id hb1mr13803969pbc.5.1338406224062; Wed, 30 May 2012 12:30:24 -0700 (PDT) Path: l9ni860pbj.0!nntp.google.com!news1.google.com!news.glorb.com!news.netfront.net!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Ada2012 : In praise of 'for ... of ... loop'... Date: Wed, 30 May 2012 12:30:21 -0700 Organization: Also freenews.netfront.net; news.tornevall.net Message-ID: References: <74e4e6b5-20bd-4388-b4a0-dfbecc8070be@googlegroups.com> <4fc4e51d$0$6566$9b4e6d93@newsspool4.arcor-online.net> <371a4b67-1969-4cd5-90f4-d58a9b276f29@googlegroups.com> NNTP-Posting-Host: 184.20.59.151 Mime-Version: 1.0 X-Trace: adenine.netfront.net 1338406223 96197 184.20.59.151 (30 May 2012 19:30:23 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Wed, 30 May 2012 19:30:23 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 In-Reply-To: <371a4b67-1969-4cd5-90f4-d58a9b276f29@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-05-30T12:30:21-07:00 List-Id: On 05/30/2012 01:10 AM, Martin wrote: > > for Comment of Header_Comments loop > Put_Line (File, Comment_Str& Comment); > end loop; > if Include_Last_Saved_Time then > Put_Line (File, Comment_Str& "Last saved: "& Image (Date => Clock)); > end if; > for Section of This.Sections loop > Put_Line (File, "["& To_String (Section.Name)& "]"); > for Pair of Section.Pairs loop > Put_Line (File, To_String (Pair.Key)& "="& To_String (Pair.Value)); > end loop; > end loop; This uses 2 inline "for" loops, one containing a nested "for loop". > Close (File); > exception > -- implementation detail > end Save; > > what we used to have (mocked up!): This uses vector iterators. While this is a nice feature, I don't think it's worth the added language complexity. In general, using "for" loops will be clearer than using iterators. In the case of vectors (or unbounded arrays, to use their correct name), one can iterate over them using "for" loops, and the use of iterators for an array abstraction is a questionable practice: for I in Header_Comments.First_Index .. Header_Comments.Last_Index loop Put_Line (File, Comment_Str & Header_Comments.Element (I) ); end loop; if ... then ... end if; for I in This.Sections.First_Index .. This.Sections.Last_Index loop Section := This.Sections.Element (I); Put_Line ... for J in Section.Pairs.First_Index .. Section.Pairs.Last_Index loop Pair := Section.Pairs.Element (J); Put_Line ... end loop; end loop; I think this is equally clear and requires no additional language complexity. Had your example used sets or maps it would have been a stronger argument. -- Jeff Carter "He didn't get that nose from playing ping-pong." Never Give a Sucker an Even Break 110 --- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---