<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Wed, 02 Jul 2003 10:16:55 +0100 
From   : "Fewell, Steve" <Steve.Fewell@...>
Subject: Re: BASIC 4 bug and more on the ON keyword!

> This is correct(ish).See page L2-45 of the Master Manuals.
> What's happening is that as the value of A% is not one of the elements
after
> the GOTO (A%=4 should also trigger the response) it scans forward looking
> for an 'ELSE' statement and executes it.The next line in the program is 40
> so that gets run too.

Yes, you're right, A%=4 also does exactly the same. Line 40 should be
executed, as the ELSE does not contain a GOTO statement. However, I don't
think the IF (2nd statement on line 30) should be executed if A% is out of
range - instead we should get 'ON Range' error.

> It's slightly dubious that the search wasn't terminated by the interpreter
> finding the "IF" and the "PRINT" tokens on the way there - it seems to use
a
> 'search and destroy' policy when looking for the ELSE.
I agree. As each line number can be represented by  an expression (but no
statements are allowed), it should just be a matter of looking for a "'",
reading the next expression, etc... And then checking for 'ELSE' when no
more expressions exist - but BASIC chooses just to search for 'ELSE' and end
of line character (CHR$(13). I think this is a flaw.

> There is a warning about using multiline statements on the page I refer
to,
> Sprow.
Yes, there is a warning about multi-line ELSE statements - but nothing about
multi line statements after the ON-statement.

Changing the program as follows demonstrates  the situation mentioned in the
manual:
10 A%=3
20 J%=1
30 ON A% GOSUB 50,60,70 ELSE IF J%=1 PRINT"J%=1" ELSE PRINT"J%=0":PRINT "a"
40 PRINT"40":END
50 PRINT"50":RETURN
60 PRINT"60":RETURN
70 PRINT"70":RETURN

When running this, the following output is generated:
70
a
40

This is correct, as the manual states the limitation of multi-line else
statements.
Also, having the ELSE at the end of the ON-statement causes the A% out of
range to function correctly, and produce the following:
J%=1
40

However, I think that if an ELSE does not exist in the ON-Statement, then
multiple statements are allowed after the ":" at the end of the ON-statement
this is what isn't working!
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>