1. Re: EUPHORIA Digest - 18 Sep 1998 to 19 Sep 1998 (#1998-125)
Quoth the raven:
>>there's nothing wrong with the way BASIC handles a FOR loop.
>
>BASIC:
>
>for i = 1 to 5
> print i
>next i
>print i
>
>I can tell you that I believed the last statement would print 5. First, i
>should be local to the loop, as Euphoria does. But the last statement
>prints 6!
>
>--Alan
The problem is in your understanding of the way BASIC operates its for
loops. For loops are used to manipulate variables in BASIC. In the above
example the loop "step" defaults to 1. The for loop repeats the loop until
i > limit. Therefore it exits on 6. Because its a variable manipulation,
and not mearly a pointer, you can also exit the loop at any time by setting
the value of i outside the limit. Such as in:
for i = 1 to 5
input "exit now? (Y/N):",a$
if a$ = "Y" or a$ = "y" then i = 5
next i
This turns out to be more complex in euphoria using a for loop. Early BASIC
implimentations only had FOR as a looping mechanism, because of this, and
low memory environments, this was a handy technique.