Date : Tue, 15 Nov 2011 21:31:42 GMT
From : jgh@... (J.G.Harston)
Subject: BBC Basic Curiosity
Darren Izzard wrote:
> I didn't discover this myself - it's based on something I found in an old
Micro User - but just out of interest, without
> trying it first, can you tell what this program will print? (BASIC 1 or 2.)
>
> 10 RESTORE 30
> 20 READ A$,B$
> 30 PRINT "?",A$,B$
> 40 PRINT A$,B$
>
> Bonus point for explaining why.
Because READ simple steps along the line the data pointer points to
looking for a "," and then reads data from there. If the byte at
the data pointer is a DATA token it is stepped over and reading
continues from there, otherwise the pointer is moved forward to a
comma, and then reading continues from there.
Consequently, if you RESTORE to a line that does not start with a
DATA token, READ thinks the data pointer is pointing to the middle
of a DATA line and steps to the next token.
--
J.G.Harston - jgh@... - mdfs.net/jgh
A Review of Sheffield City Council's Members' Allowances Scheme
See http://mdfs.net/payreform