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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8b8f4ad9d302b143 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-04 22:14:37 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: ada loops Message-ID: <9aktdvc3gcnidr89ipkamofj8mrc7n92jo@4ax.com> References: X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 05 Jun 2003 05:14:36 GMT NNTP-Posting-Host: 12.89.164.57 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1054790076 12.89.164.57 (Thu, 05 Jun 2003 05:14:36 GMT) NNTP-Posting-Date: Thu, 05 Jun 2003 05:14:36 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:38656 Date: 2003-06-05T05:14:36+00:00 List-Id: On 30 May 2003 13:25:31 -0400, Stephen Leake wrote: [for variable local to loop] > I don't remember how Pascal did this; I suspect the loop variable was > not a new declaration. In standard C++, the loop variable is a new > declaration (as in Ada), but in early versions of C++, it wasn't. > Not exactly. In C++ you have an explicit choice: 1) if you write e.g. for( i = 0; i < 10; i++ ) ... it uses an existing variable (which must be) already available (declared). 2) if you write e.g. for( int i = 0; i < 10; i++ ) ... it creates a new variable. But what happens thereafter varies: 2A) in pre-standard C++ (aka ARM) this declaration remains in scope (and the variable valid) after the loop, to the end of the containing { } block -- so you can't declare another variable (or anything) with the same name, in particular you can't do another for ( int i = 0 ...; 2B) in standard C++(88) it is declared and exists only to the end of the loop. In all cases, you need to match the type of the loop variable to the range of values assigned; this isn't determined for you automatically, nor checked for overflow (in practice, theoretically it's allowed). C99, BTW, adds to C the 2B variant. - David.Thompson1 at worldnet.att.net