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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e511f3ccb3da24af X-Google-Attributes: gid103376,public From: Matthew J Heaney Subject: Re: How to make like Fortran "do i = 1,20,2" Date: 2000/07/27 Message-ID: <7rhf9bb362.fsf@butter.albany.duck.com>#1/1 X-Deja-AN: 651616357 Sender: mheaney@butter.albany.duck.com References: <8lpcbe$40n$1@news.uit.no> <39805669.3E7CF6CF@lmtas.lmco.com> X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 964741747 208.136.9.227 (Thu, 27 Jul 2000 16:49:07 PDT) Organization: EarthLink Inc. -- http://www.EarthLink.net NNTP-Posting-Date: Thu, 27 Jul 2000 16:49:07 PDT Newsgroups: comp.lang.ada Date: 2000-07-27T00:00:00+00:00 List-Id: Gary Scott writes: > Hmmm, these and similar examples posted do not make Ada look very > elegant...it makes a very simple concept seem somewhat convoluted. This "very simple concept" is a major source of bugs -- that's why it's not in the language. If you want to increment by 2 through the loop, it's simple enough: declare I : Positive := A'First; begin while I <= A'Last loop ... A(I) ... I := I + 2; end loop; end; QED If you want to do odd-ball things, then sometimes that requires extra work. The common things (like incrementing the loop index by 1) are easy to do. I can't even remember the last time I had to iterate over an array by an increment other than 1. Consider this analogy. Suppose you want to iterate over a linked list: list intList; ... list::iterator iter = intList.begin(); In the normal case, when you increment by 1, it's simple: while (iter != intList.end()) { ... iter++; } Asking how to iterate in increments of 2 is like asking, How do I visit every other list element? That's an odd-ball thing to do, so you have to do extra work. (Try it and you'll see.)