8

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

2 Answers 2

4

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...)

1
  • 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). Commented Apr 3, 2018 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .