From: wdl39!mab@ford-wdl1.arpa (Mark A Biggar)
Subject: Re: loop indices
Date: 17 Apr 92 20:00:20 GMT [thread overview]
Message-ID: <1992Apr17.200020.26094@wdl.loral.com> (raw)
In article <70482@ut-emx.uucp> hasan@emx.utexas.edu (David A. Hasan) writes:
>Suppose I have a matrix manipulation routine which must
>loop over the elements of several different ARRAYs.
>My question stems from the observation that unless the
>ARRAYs have the same bounds on their indices, I won't
>be able to index into all of them using a single FOR-LOOP
>index. Consider this example:
> DECLARE
> TYPE Vector IS ARRAY( Positive RANGE <> ) OF Integer;
> p1 : CONSTANT Positive := 21;
> p2 : CONSTANT Positive := 51;
> size : Natural := 5;
>
> v1 : Vector( p1 .. (p1+size-1) );
> v2 : Vector( p2 .. (p2+size-1) );
> BEGIN
> FOR i IN 1..size LOOP
> v2(i) := v1(i); -------------------(!)
> END LOOP;
> END;
>Obviously, I'll have constraint error problems here.
>The problem is not solve, either, if I replace the FOR
>LOOP by
> FOR i IN v2'RANGE LOOP
>since the index *still* won't work in <v1>.
What's wrong with using:
FOR i IN 1..size LOOP
v2(p1+i-1) := v2(p2+i-1);
END LOOP;
or
FOR i IN v2'RANGE LOOP
v2(i) := v1(i-p2+p1);
END LOOP;
--
Mark Biggar
mab@wdl1.wdl.loral.com
next reply other threads:[~1992-04-17 20:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-04-17 20:00 Mark A Biggar [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-04-20 14:00 loop indices Robert Firth
1992-04-20 16:39 David A. Hasan
1992-04-20 21:11 David A. Hasan
1992-04-22 21:02 Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox