Date : Fri, 11 Feb 2005 03:59:13 -0800 (PST)
From : Darren Izzard <zysyshelp@...>
Subject: Re: programming tips
>Could you please explain this PROC idea, line 170 and
>line 180.
>Sorry about this, but I'm trying to learn so I'm not
>too good.
First of all, I should say I sent that program to Tom
privately, which is why it seemed to come out of
nowhere! Secondly, there is one mistake which I
corrected in a mail to Tom: it should read MODE 1 and
not MODE 4! (Otherwise the colours don't work.)
The reason for using the PROC (procedure) was to avoid
the GOTOs which had been used to skip in and out of
the REPEAT/UNTIL loop. (Arguably, my use of END inside
a loop isn't much better!) GOTOs are frowned upon at
the best of times, of course, but Tom's original use
of GOTO would have caused the same REPEAT statement to
be encountered multiple times during the program's
execution. This would cause BASIC to set up lots of
loops, and basically if you kept using the program for
a long time, you would run out of memory.
The main reason for using a procedure is it clarifies
the structure - at least, to me!
The point of lines 170 and 180 is to wait for one of
the following keys to be pressed: Y, y, N or n.
Line 170 (A$=GET$) simply waits for a keypress, and
stores the character that was pressed in A$, with no
need for pressing RETURN. I notice the INSTR technique
in 180 has also been used by other people who
submitted versions. Since A$ only contains one
character, we can check if it is Y, y, N or n by using
INSTR to see if A$ is found in the string "YyNn". If
it is not, then INSTR will return zero, in which case,
we wait for another keypress.
I hope that helps.
--Darren