6

In Applesoft BASIC, does combining statements into a single line speed up execution?

For example, would this:

10 PRINT "HELLO WORLD" : FOR I = 1 TO 100 : PRINT I : NEXT I

Run faster than this:

10 PRINT "HELLO WORLD"
20 FOR I = 1 to 100
30 PRINT I
40 NEXT I
3

Yes


Handling line end and a new lines start does take more time for the interpreter than skiping a colon.

8

Yes. Replacing NEXT I with NEXT will also help.

One way to evaluate this is to throw a speaker click (PEEK -16336) into the loop and listen. The faster the loop, the higher the pitch. (Then try it with SP=-16336 outside the loop and PEEK SP in the loop, and note the effect that has...)

  • Counterintuitively, on Commodore BASIC, "NEXT" is faster than "NEXT I". "NEXT" simply pops off the most recently nested FOR variable; "NEXT I" has to do pull I off the stack and then push back any more recent FOR loops (which can create some program execution fun). – Jim MacKenzie Apr 3 '18 at 16:48

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.