I have just come across a feature in the behaviour of NEXT in FOR-loops
which is a bit puzzling. If NEXT is invoked from the body of the loop with
the counter NOT on its final value, control ends up in the loop with the
counter reset at its next value - just what one would hope for. However,
if the counter IS on its final value, the same happens except that the
counter is not reset. Try entering even and odd integers in the program
below (I am using QPC2v2.00 and SMSQ/e v2.98) :
100 CLS : INPUT '>';n
110 FOR i=0 TO n
120 IF i MOD 2=0 THEN NEXT i
130 PRINT i
140 NEXT i
150 PRINT 'done'
160 END FOR i
To get round this in a piece of code I'm currently engaged on, I have had
to test for i=n when the exception arises and use EXIT i when on the final
loop. Comments anyone?
Christopher Cave