Tips for golfing in QBasic What general tips do you have for golfing in QBasic? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to QBasic (e.g. "remove comments" is not an answer).

Tips pertaining to the QB64 emulator are also welcome. It has some extra features that aren't in Microsoft QBasic.
Know your looping constructs

QBasic has several looping constructs: FOR ... NEXT, WHILE ... WEND, and DO ... LOOP. You can also use GOTO or (in some situations) RUN to loop.


FOR ... NEXT is pretty good at what it does. Unlike in Python, it's almost always shorter than the equivalent WHILE or GOTO loop, even when it gets a little fancier:

FOR i=1TO 19STEP 2:?i:NEXT
i=1:WHILE i&lt;20:?i:i=i+2:WEND
i=1:9?i:i=i+2:IF i&lt;20GOTO 9


Note that you don't need to repeat the variable name after NEXT, and you can eliminate space between numbers and most following keywords.
WHILE ... WEND is good for when you have a loop that might need to execute 0 times. But if you know the loop will execute at least once, GOTO might be one byte shorter:

WHILE n&gt;1:n=n\2:WEND
1n=n\2:IF n&gt;1GOTO 1

I only use DO ... LOOP for infinite loops (except where RUN can be used instead). While it costs the same number of characters as an unconditional GOTO, it's a little more intuitive to read. (Note that "infinite loop" can include loops that you break out of using a GOTO.) The DO WHILE/DO UNTIL/LOOP WHILE/LOOP UNTIL syntax is too verbose; you're better off using WHILE or GOTO as appropriate.
GOTO is, as mentioned above, the shortest general way to write a do/while loop. Use single-digit line numbers instead of labels. Note that when a GOTO is the only thing in the THEN part of an IF statement, there are two equally terse shortcut syntaxes available:

IF x&gt;y GOTO 1
IF x&gt;y THEN 1


GOTO can also be used to create more complicated control flows. The naysayers refer to this as "spaghetti code," but this is code golf: unreadability is almost a virtue! GOTO pride!
RUN is useful when you need to jump to a fixed place in the program and you don't need to keep any of the variables' values. RUN by itself will restart the program from the top; with a label or line number, it will restart at that line. I've mainly used it to create stateless infinite loops.