comp.lang.ada
 help / color / mirror / Atom feed
From: Dave Thompson <david.thompson1@worldnet.att.net>
Subject: Re: ada loops
Date: Thu, 05 Jun 2003 05:14:36 GMT
Date: 2003-06-05T05:14:36+00:00	[thread overview]
Message-ID: <9aktdvc3gcnidr89ipkamofj8mrc7n92jo@4ax.com> (raw)
In-Reply-To: uvfvsmjn8.fsf@nasa.gov

On 30 May 2003 13:25:31 -0400, Stephen Leake <Stephe.Leake@nasa.gov>
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



  parent reply	other threads:[~2003-06-05  5:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-30 15:44 ada loops Roman V. Isaev
2003-05-30 16:00 ` Bill Findlay
2003-05-30 16:17 ` Robert A Duff
2003-05-30 16:46   ` Bill Findlay
2003-05-30 16:51   ` Bill Findlay
2003-05-30 17:25 ` Stephen Leake
2003-05-30 19:40   ` Robert A Duff
2003-05-30 21:33     ` Pascal Obry
2003-05-31 16:19       ` Robert A Duff
2003-05-31 16:29       ` Robert A Duff
2003-05-30 21:38     ` Simon Wright
2003-05-30 21:51       ` chris.danx
2003-05-31  6:40         ` Pascal Obry
2003-05-31 16:21         ` Robert A Duff
2003-06-02 16:39       ` Stephen Leake
2003-05-31 16:24     ` Oliver Kellogg
2003-05-31 23:15       ` Preben Randhol
2003-06-05  5:14   ` Dave Thompson [this message]
2003-06-05 18:15     ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox