Do Loop

32 views
Skip to first unread message

Craig Lindley

unread,
Sep 20, 2018, 10:24:47 AM9/20/18
to pforthdev
What should be the behavior of this loop?

: test 1 1 do i . loop ;

I was under the impression that the loop should not execute but it runs to infinity

Phil Burk

unread,
Sep 20, 2018, 12:46:31 PM9/20/18
to pforthdev
In some older Forths, "1 1 DO" would skip the loop. But in the newer ANSI Forths, it is expected to loop forever.

I think that is odd, but there is probably a good reason.
You may want to use ?DO because it will check for equal indices and skip the loop when you expect.

Phil Burk


--
You received this message because you are subscribed to the Google Groups "pforthdev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pforthdev+...@googlegroups.com.
To post to this group, send email to pfor...@googlegroups.com.
Visit this group at https://groups.google.com/group/pforthdev.
For more options, visit https://groups.google.com/d/optout.

Helmut Eller

unread,
Sep 20, 2018, 1:52:35 PM9/20/18
to Craig Lindley, pforthdev
In addition to what Phil said, I would add "always use ?DO instead of
DO" and "never use N +LOOP with negative N".

Helmut
Reply all
Reply to author
Forward
0 new messages