comp.lang.ada
 help / color / mirror / Atom feed
From: Jean-Pierre Rosen <rosen@adalog.fr>
Subject: Re: loop variable
Date: Tue, 30 Sep 2008 09:52:26 +0200
Date: 2008-09-30T09:52:26+02:00	[thread overview]
Message-ID: <urlsbg.vf2.ln@hunter.axlog.fr> (raw)
In-Reply-To: <48e0b042$0$26352$4d3efbfe@news.sover.net>

Peter C. Chapin a �crit :
> jedivaughn wrote:
> 
>> What data_type is a loop variable
>> as an example
>> for i in 1..10
>> what data type is i?
> 
> The subtype of a loop variable is the subtype used to define the loop's
> range. Something like '1..10' is shorthand for 'Integer range 1..10' and
> so in your example I has type Integer.
> 
> However, I echo the comments Georg Bauhaus made in his post: be careful
> with conversions. They often (not always) mean you haven't defined your
> types properly or that you haven't declared your variables with the most
> appropriate types.
> 
To concur with that:
The declaration of a loop control variable is the only case in Ada where 
you can define an object without giving (explicitely) its type in the 
same declaration - and it's unfortunate. Remember that you are always 
allowed (although not required) to specify the type explicitely:
    for I in My_Integer_Type range 1 .. 10 loop

Of course, there is a rule in AdaControl to check for loops that don't 
follow this advice ;-)

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



  reply	other threads:[~2008-09-30  7:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-29  1:54 loop variable jedivaughn
2008-09-29  3:20 ` george.priv
2008-09-29  8:52   ` Georg Bauhaus
2008-09-29 10:38 ` Peter C. Chapin
2008-09-30  7:52   ` Jean-Pierre Rosen [this message]
2008-09-29 14:54 ` Adam Beneschan
replies disabled

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