[Coco] Re: More on FOR-NEXT

Arthur Flexser flexser at fiu.edu
Tue Jun 13 05:30:01 EDT 2006


But using his first example rather than the second doesn't affect anything
you've mentioned.  Merely setting the loop variable to the value it would
normally have on loop completion doesn't affect the presence of leftover loop
stuff on the stack if you exit the loop with a GOTO.

Art

On Mon, 12 Jun 2006, Aaron Banerjee wrote:

> 
> Actually, I think it might make a difference.  A few years ago, I wrote a
> BASIC program to solve the "8 Queens" problem (find all 92 ways to put 8
> queens on a chess board such that none can attack any other -- I'll send
> the program to anyone interested if I can find it -- it's in one of the
> last issues of "The World of '68 Micros").  My program had more to do with
> fooling with GOSUB (e.g. goto-ing out before hitting the RETURN statement,
> etc), but I thought FOR-NEXT worked in the same manner.
> 
> If my memory serves me, if you GOTO out of a for loop, and then hit a
> "NEXT", you'll bounce back up to the calling FOR statement, which may or
> may not be what you want to do.  If you've exited by setting the variable,
> in your case to 11 and hitting the next, subsequent "NEXT" statements will
> give you an ?NF ERROR  (unless, of course, you have other FOR loops).  I'm
> not 100% sure of this, but now I'm curious enough to break out the coco
> and see...
>                          - Aaron
> 
> 
> ----------------- Original Message ----------------------
> When forcing an exit from a FOR-NEXT loop, does it make any difference 
> to do a clean exit, by manually changing the variable value and GOTOing 
> to the NEXT line, or is it the same that just GOTO?
> Ex:
> 10 FOR A=1 TO 10
> 20 IF P=3 THEN A=11:GOTO  30
> 30 NEXT A
> 40 REM REST OF THE PROGRAM
> 
>  is any better than
> 
> 10 FOR A=1 TO 10
> 20 IF P=3 THEN 40
> 30 NEXT A
> 40 REM REST OF THE PROGRAM
> 
> Diego
> 
> 
> 
> -- 
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
> 




More information about the Coco mailing list