[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Advanced Programming Structures
A couple of notes...
First of all, why do in a dozen lines of code what you could do more
easily in two or three? The example was "DO...UNTIL X<>0" and included a
FOR...NEXT loop to emulate it. In Applesoft, you're a whole lot better
off simulating that structure with...
60000 X = 0
60005 (doing stuff that may or may not change the value of X)
.
.
.
60050 IF X <> 0 THEN RETURN : REM Or IF X<>0 THEN 60060 if not a sub
60055 GOTO 60005
Yes, it includes the dreaded GOTO (twice if not called with a GOSUB, in
fact!) but while that will make PASCAL programmers sneer at you, it will
run more efficiently in Applesoft because the program structure involves
fewer instructions, fewer compares, and no danger of leaving crud on the
system stack.
On a related note, it is VERY BAD FORM to jump out of a FOR...NEXT loop
anywhere other than at NEXT. Not only that, it's a good habit to get into
to make sure that there is one and only one NEXT instruction. Using
multiple NEXTs will work, but because the exact performance of the routine
may be unpredictable, you increase your chances of triggering a ?NEXT
WITHOUT FOR error. Jumping out of a FOR...NEXT loop without allowing it
(or forcing it) to complete will, at the very least, create memory leaks,
which is the last thing you want when there is a very good chance that
your program only has $17FF bytes available for code and $5CFF bytes
available for variable storage (assuming DOS 3.3 and a desire to not
clobber the hi-res screen).
I should also note that in ObjectPAL, some jerk left out the GOTO
instruction. So I have Paradox scripts which have "IF..ENDIF" constructs
from hell because there is no way to simply jump out of the program
structure. Actually makes the program structure HARDER to read.
--Dave Althoff, ][.
--
/X\ _ _ _ *** Now open every day! ***
/XXX\ /X\ /X\_ _ /X\__ _ _ _____
/XXXXX\ /XXX\ _/XXXX\_ /X\ /XXXXX\ /X\ /X\ /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX