This would work in most traditional BASICs with a command line user interface:
10 LIST
But that's cheating. And anyway, it won't work in more modern
BASICs such as Microsoft QBasic, which has a text editor as its programming
interface and so hasn't bothered with a LIST
command. But
here is a QBasic quine that isn't cheating:
FOR n = 1 TO 9
READ s$
PRINT s$
NEXT n
RESTORE
FOR n = 1 TO 9
READ s$
PRINT "DATA "; s$
NEXT n
DATA FOR n = 1 TO 9
DATA READ s$
DATA PRINT s$
DATA NEXT n
DATA RESTORE
DATA FOR n = 1 TO 9
DATA READ s$
DATA PRINT "DATA "; s$
DATA NEXT n
"What's happened to the line numbers?" I hear you ask. A neat feature of QBasic is that it doesn't require them, making it that bit easier to write a quine. Here's a shorter and similar one:
FOR n = 1 TO 5
DATA FOR n = 1 TO 5
READ s$
DATA READ s$
PRINT s$
DATA PRINT s$
PRINT "DATA "; s$
DATA PRINT "DATA "; s$
NEXT n
DATA NEXT n
Here's a shorter one. The interior line break corresponds to that produced by QBasic's automatic string wrapping in the default 80-column mode:
p$=":FOR n=1 TO 2:?RIGHT$(p$,3);CHR$(34);LEFT$(p$,55);:NEXTp$="
:FOR n=1 TO 2:?RIGHT$(p$,3);CHR$(34);LEFT$(p$,55);:NEXT
Of course after QBasic has 'formatted' the code, the code it's running isn't quite what's output anymore. Not to worry:
p$ = ": FOR n = 1 TO 2: PRINT RIGHT$(p$, 5); CHR$(34); LEFT$(p$, 70); : NEXTp$ = ":
FOR n = 1 TO 2: PRINT RIGHT$(p$, 5); CHR$(34); LEFT$(p$, 70); : NEXT