Re: for Iteration bug

From: Kish Shen <ks15_at_icparc.ic.ac.uk>
Date: Sat 05 Mar 2005 09:40:57 PM GMT
Message-Id: <E1D7h17-0006nm-NI@tempest.icparc.ic.ac.uk>
Hi,

I am cross-posting my answer to eclipse-users mailing list, as I
think this is of general interest.

Krzysztof Apt wrote:

>In Modula and Algol-like languages we can write
>
>FOR i:=1 TO N DO
>  FOR j:=1 TO M DO
>    ...
>  END
>END
>
>and this is just a nested for-loop. I assume that the right
>way to write it in Eclipse is *only* with *nested* for loops
>and not iterated ones .
>in which one has to pass the outer parameter (I) as param(I).
>Am I right?

Yes and no. :-)

A) No, in that in the latest version of ECLiPSe (5.8), you can write
your example as:

(multifor([I,J], [1,1], [N,M]) do ...)

and in fact this can be simplified to:

(multifor([I,J], 1, [N,M]) do ...)

as the starting values for I and J are the same.

For example:

[eclipse 1]: (multifor([I,J], 1, [2,4]) do writeln(I-J)).
1 - 1
1 - 2
1 - 3
1 - 4
2 - 1
2 - 2
2 - 3
2 - 4

B) Yes, you are right, in that if you want to write nested do loops, you
need to write them as you stated. The above example in nested do loops:

(for(I, 1, 2) do
   (for(J, 1, 4), param(I) do
        writeln(I-J)
   )
)

and *NOT*:

(for(I, 1, 2), for(J, 2, 4) do ...)

Cheers,

Kish

 
Received on Sat Mar 05 21:48:31 2005

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:34 PM GMT GMT