-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Jun 29, 2005, at 2:19 AM, Frank Heckenbach wrote:
GPC accepts the following program, but produces quite silly results:
program Foo;
var a: array [1 .. 2] of Integer value (0, 0); i: Integer;
begin i := 1; for a[i] := 1 to 10 do begin WriteLn (i, ' ', a[i]); if a[i] = 5 then i := 2 end end.
The problem is that it evaluates the index i each time, not once before the loop. It would be possible to fix it, but do we really want that? Neither BP nor CP/EP allow it, they allow only identifiers in for-loops.
Waldek and I see no need for such a feature. (If it made it possible to nest a compile-time-unknown number of `for' loops, I could see some point, but of course, it doesn't.)
Actually, I think it does (untested, though):
CONST max_depth = 100;
FUNCTION Multi_For(depth, limit : INTEGER) : LONGINT; VAR i : INTEGER; a : ARRAY[1..max_depth] OF INTEGER; v : LONGINT;
BEGIN { setup } i := 1; v := 0;
{ the loops } FOR a[i] := 1 TO limit DO BEGIN IF (i < depth) THEN BEGIN INC(i); a[i] := 1 END ELSE BEGIN { actual loop stuff } v := v + a[i];
{ handle reduction in depth at end of loop } IF (a[i] = limit) AND (i > 1) THEN DEC(i) END END;
Multi_For := v END;
- ----------------------------------------------------------- Frank D. Engel, Jr. fde101@fjrhome.net
$ ln -s /usr/share/kjvbible /usr/manual $ true | cat /usr/manual | grep "John 3:16" John 3:16 For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. $
___________________________________________________________ $0 Web Hosting with up to 200MB web space, 1000 MB Transfer 10 Personalized POP and Web E-mail Accounts, and much more. Signup at www.doteasy.com