[Coco] Re: More on FOR-NEXT

Aaron Banerjee spam_proof at worldnet.att.net
Mon Jun 12 20:36:54 EDT 2006


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





More information about the Coco mailing list