comp.lang.ada
 help / color / mirror / Atom feed
From: nobody@REPLAY.COM (Anonymous)
Subject: Re: Curious Question
Date: 1997/12/09
Date: 1997-12-09T00:00:00+00:00	[thread overview]
Message-ID: <199712091633.RAA12253@basement.replay.com> (raw)
In-Reply-To: 66757i$mk5$1@swlab1.msd.ray.com


On 4 Dec 1997 20:53:06 GMT, car@swl.msd.ray.com (Chad Reichenbach
{81726}) wrote:

> I have a question I can'f figure out.  If I have the following code:
> 
>   type My_Type is (obj1, obj2 obj3, obj4, obj5, obj6);
>   subtype My_Subtype is My_Type range obj1 .. obj4;
> 
> My question is, I need a new subtype that ranges from obj4 to obj1.
> Will the declaration
> 
>   subtype Second_Subtype is My_Subtype
>           range My_Subtype'last .. My_Subtype'first
> 
> do that?  If not is there a way to do it without defining a new
> enumeration?
> 
> The type would be used in a loop that loops through the enumeration
> objects using S'succ(S).
> 

Not necessary:

   for S in reverse My_Subtype loop

The first time through the loop, S = My_Subtype'Last; the next time, S =
My_Subtype'Pred (My_Subtype'Last); ...; the last time, S =
My_Subtype"First.

If you need to manually work through the loop, use 'Pred instead of
'Succ:

   S := My_Subtype'Last;

   loop
      -- Do stuff with S

      exit when S = My_Subtype'First;

      S := My_Subtype'Pred (S);
   end loop;

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"We burst our pimples at you."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/




      parent reply	other threads:[~1997-12-09  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-04  0:00 Curious Question Chad Reichenbach {81726}
1997-12-05  0:00 ` Tucker Taft
1997-12-09  0:00 ` Anonymous [this message]
replies disabled

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