# A Quine on Every Line

Your goal is to create a program that prints itself indefinitely, with a new line after each one. Thus, if your program is a one-liner, it would be repeated on every line of the output.

### Example

Program:

A


Output:

A
A
A
...


### Rules

• It must be a complete program, not a snippet or function.
• The program should loop forever without stack-overflow or recursion limit errors.
• Output is to stdout or closest alternative.
• No program input is accepted.
• Standard loopholes are disallowed, such as opening the program's file or accessing an external resource. Empty programs are disallowed as a standard loophole.
• If your program code ends with a trailing newline, this does not count as the necessary newline between quines, and you must print another.
• - Shortest code wins!
• The title looks like only one-line programs qualify? – Paŭlo Ebermann Sep 16 '15 at 18:40
• @PaŭloEbermann Then read the problem description. It's a witty title because it rhymes. Here's an example of a valid multi-line program: codegolf.stackexchange.com/a/57985/34718 . You can't expect to know everything about a challenge by only reading the title. – mbomb007 Sep 16 '15 at 18:51
• @PaŭloEbermann It's just while(1)println(your_code); – Matthew Roh Apr 21 '17 at 23:41

# Fission, 7 bytes

'!+!NR"


A rather simple modification of the shortest Fission quine I have found so far: I'm simply using the non-destructive ! instead of O and added an N for newline.

So all in all, here is how it works: control flow starts at the R with a right-going atom. " toggles string mode, which means everything until the next " is printed: in this case '!+!NR. That leaves the " and the newline to be printed. '! sets the atom's mass to 33, + increments it to 34 (the character code of ") and ! prints the quote. N prints a newline, and R is now a no-op in this case, so the loop starts over.

The following 7-byte solution also works:

"NR'!+!


# ><>, 16 bytes

'ard3*o50l2)?.~~


The traditional ><> quine uses too many os, so we use a loop for printing. Before each jump we push 5 and 0 (the coordinates of where to jump to), after which we either jump with . if there's still something to print, or pops the top two values with ~~.

(Reverted to the 16 version since I forgot about the stack overflow rule.)

• An alternative is "ar00go50l2)?.[, right? – mbomb007 Sep 11 '15 at 16:35
• @mbomb007 I guess, but I prefer d3* since g reads your own source code – Sp3000 Sep 11 '15 at 16:38

# CJam, 13 bytes

{_o"_g
"o1}_g


The online interpreter doesn't print anything before the program terminates, so you'll have to test this in the Java interpreter.

## Explanation

Finally a generalised CJam quine which doesn't end in _~.

{_o"_g
"o1}


This simply pushes a block. _g duplicates the block and executes it repeatedly while the top of the stack is truthy (discarding the condition).

Now inside the block, the other copy of the block is still on the stack. We duplicate and print it with _o and then we print _g followed by a newline (the required extra newline between quines) with "_g\n"o. Finally we push a 1 onto the stack for the loop to repeat, because unfortunately, blocks aren't truthy (or falsy) in CJam.

# Python 2, 39

Not a very interesting task in Python as it's trivial to add the while loop to a normal quine.

c='while 2:print"c=%r;exec c"%c';exec c

• Doesn't this blow the stack? – Jesan Fafon Sep 11 '15 at 21:42
• @JesanFafon No, if you tried it you would see that it doesn't. There is no recursion. – feersum Sep 11 '15 at 21:53

# Perl 5.10+, 40 37 bytes

$_=q{say"$_=q{_};eval"while 1};eval  or (also 37 bytes) _=q{{say"$_=q{$_};eval";redo}};eval


Invoke with the -M5.010 or -E command line flag, e.g.

$perl -E '$_=q{say"$_=q{_};eval"while 1};eval' _=q{say"$_=q{$_};eval"while 1};eval$_=q{say"$_=q{_};eval"while 1};eval _=q{say"$_=q{$_};eval"while 1};eval ...  Thanks to Ilmari Karonen for shaving off 3 bytes from my original solution, which was: eval while$_=q{say"eval while$_=q{_}"}  This, as well as the shorter 37-byte solutions above, are all simple variations of the following quine, which I first saw in one of Ilmari's other posts: _=q{say"$_=q{$_};eval"};eval  Since all I added in my original solution was a while loop, he really deserves most of the credit. :-) • Nice, and thanks for the credit. :-) The original quine is my own design, although someone else may well have independently discovered it earlier. BTW, $_=q{say"$_=q{_};eval"while 1};eval or _=q{{say"$_=q{$_};eval";redo}};eval would be a few bytes shorter. ($_=q{say"\$_=q{$_};eval";eval};eval would be even shorter yet, but I suspect it will eventually run out of stack.) – Ilmari Karonen Sep 15 '15 at 15:07
• I was hoping you would show up! Thank you for the shorter solutions, I figured you would come up with something better; but I was so blown away by this when I saw it in the answer I linked to, I just had to try it myself. :) To be honest, I still haven't quite wrapped my head around quines, but the additional answers give me more to look at. I wasn't sure if you originated this because I saw you credited with the shortest non-cheating Perl quine ever(?!) on this page, but there's no attribution for this quine (using print instead of say). – ThisSuitIsBlackNot Sep 15 '15 at 16:03
• btw, the last one does indeed segfault after running for a while. Thanks again, @Ilmari! – ThisSuitIsBlackNot Sep 15 '15 at 16:03
• Actually, I take that somewhat back -- I'm definitely not the first to invent that quine, and since I'd definitely seen it before (I posted the one I do claim some credit for in the same thread), it's quite likely that I subconsciously remembered it from that thread, or from somewhere else. – Ilmari Karonen Sep 15 '15 at 16:16
• Alright, I've left the origin unspecified. Regardless, thank you for the 3 bytes and thank you for the original inspiration. – ThisSuitIsBlackNot Sep 15 '15 at 16:39

# Self-modifying Brainf*** (SMBF), 14 bytes

The trailing newline \n needs to be a literal, Unix, newline (ASCII code 10).

[<[<]>[.>]<.]\n


### Explanation:

The code moves the pointer to the far left of its source code, then prints it all, including the newline (twice b/c of the rule). The loop continues.

• You mean, it has to be \r? – Ismael Miguel Sep 11 '15 at 17:27
• @IsmaelMiguel No. \n is a new line, and is ASCII code 10, so a hex-dump of the source code would have the value 0A for that byte. code.cside.com/3rdpage/us/newLine.html – mbomb007 Sep 11 '15 at 18:19
• @IsmaelMiguel Not true. When you type code, you actually hit the enter key for a newline. \n generally counts as 2 characters, and 2 bytes in your code. I typed it this way for readability, since the formatting doesn't work well for showing a blank line at the end of my source code. And so I had to specify that it was ONE byte, not two. – mbomb007 Sep 11 '15 at 19:46
• \n is always a single character, called a linefeed. A newline, however, is a platform-dependent sequence of bytes. – Dennis Sep 11 '15 at 22:32
• @Dennis Maybe so, but I don't care. I don't call / a "Solidus", and I don't know anybody who does. "Newline" starts with an n, and that's the escape character, so that's what I call it. It's closer to "line feed" than it is to "carriage return". – mbomb007 Sep 12 '15 at 1:02

# PowerShell, 143 Bytes

$d='$d={0}{1}{0}{2}while(1){3}Write($d -f [char]39,$d,"n",[char]123,[char]125){4}'
while(1){Write($d -f [char]39,$d,"n",[char]123,[char]125)}


Based off the Rosetta Code PowerShell quine, I'm pretty confident this isn't the shortest possible. String replacement formatting in PowerShell is icky for this, because the same delimiters for where to put the replacements {} also delimit code blocks while{}, so we have to use [char] casting, which bloats the code a bunch.

First time I've tried something like this and I'm not sure if follows all the rules as it is a couple of lines. The newline was a bit of a pain.

(::a~*S:a~*^
)::a~*S:a~*^

• @mbomb007 The output per iteration is the two lines of the program. I tested it here – MickyT Sep 12 '15 at 3:42

# Befunge, 30 20 bytes

<,+55,*2+98_ #!,#:<"


A variation of a popular befunge quine that prints out a newline and pops -1 on the stack if it finishes the line.
Unfortunately, Befunge gets verbose when doing things in one line. I tried to remove all of the launchpads (#) that i could, but some had to be left in to skip certain commands (like ,).

Changes:

30-20 -> changed the base quine to a custom one I made that uses string input. This way, the branching is a lot easier.

Old:

:0g,:93*>0-10 #,+$#: #5 _1+>  I don't think this is optimal, but it's acceptable for now. # K, 30 bytes {f:$_f;{x}{0:f,"[]\n";1}/1}[]


## R, 34 bytes

repeat{write(commandArgs()[5],'')}


to invoke from the command line as follows:

Rscript -e "repeat{write(commandArgs()[5],'')}"


# ><>, 31 29 bytes

A simple modification of the traditional ><> quine.

"ar00gc0.0+efooooooooooooooo|


To run, paste it here, click 'Submit', then 'Start' (running without animation doesn't work). Feel free to increase the execution speed.

• "ar00gc0.0+feooooooooooooooo| is two bytes shorter. – cole Sep 12 '15 at 3:56
• @Cole Thanks. I had thought about the mirror, but forgot to change it after getting side-tracked on a different challenge. – mbomb007 Sep 12 '15 at 19:38
• 20 bytes – Jo King Apr 15 '19 at 6:58
• @JoKing There's already a shorter ><> solution. – mbomb007 Apr 15 '19 at 14:30

# Python 2, 48 bytes

c='c=\'%s\';while 1:print c%c';while 1:print c%c


# GolfScript, 16 bytes

{.".do
":n\p}.do


This ended up looking a lot like Martin Büttner's CJam entry. An interesting feature is that, as it turns out, the shortest way to append ".do" to the block when it's printed is to assign it to the line terminator n. (Of course, we also need to include an actual newline in the string, to replace the one n normally contains.) The same string (being truthy in GolfScript) is also left on the stack for the do loop to pop off, ensuring that the loop runs forever.

# Brachylog, 16 bytes

∋"∋~kgjẉ₁⊥"gjẉ₁⊥


You can't quite try it online, but I have verified that it works on my installation.

# Brachylog, 18 bytes

∋"∋~kgjw₁⊥~n"gjw₁⊥


Try it online!

Adapted from the alternate version of this quine, with a backtracking hack I had initially devised for bogosort of all things. Spends two bytes on ~n because ẉ (the usual means for printing with a trailing newline) hits some odd issues with character encoding on TIO, and an actual newline inserted into the string literal gets printed through ~k as \n.

               w      Print
"∋~kgjw₁⊥~n"         "∋~kgjw₁⊥~n"
∋                     which is an element of
the (unused and unconstrained) input
₁     formatted
~n          (so that the ~n is replaced with a newline)
gj       with itself
~k                 (so that the ~k is replaced with the string in quotes),
⊥    then try again.


Since w₁ takes input as a list [string to be formatted, formatting arguments], wrapping a string in a list with g then concatenating it to itself with j allows it to be formatted with itself. And since no input is given to the program, the input variable which is implicitly present at the beginning of the program can take on any value, so it can be constrained to one of the infinitely many lists which contain "∋~kgjw₁⊥~n" as an element, creating a single choice point to be backtracked to when after printing its source the program hits ⊥.

# Gol><>, 10 bytes

"r2sslRoao


Try it online!

This can probably be golfed down more

# Python 3.6, 48 43 bytes.

-5 bytes thanks to @Jo King

x='while 1:print("x=%r;exec(x)"%x)';exec(x)

• You can use %r to save on escaping those 's. 43 bytes – Jo King Apr 15 '19 at 9:50
• which gives 41 for python 3.8 :P – ASCII-only Apr 16 '19 at 12:48

# BASH, 76 bytes

Just couldn't resist, especially with PowerShell here :)

while true;do
a ()
{
echo while true\;do
declare -f a
echo a\;done
}
a;done


The whitespace is important for an EXACT copy.

# Javascript (ES6), 64

for(;;(_=>console.log(for(;;(_=>${arguments.callee})());))());  Alternatively (also 64) a="for(;;)console.log(a=${JSON.stringify(a)};eval(a))";eval(a)

• Wouldn't the alternative cause a stack overflow? – Patrick Roberts Sep 13 '15 at 13:23
• No. There is no recursion so nothing should be adding up on the stack. – DankMemes Sep 13 '15 at 15:27
• Okay, well I just tested both of them, you are correct about the alternative solution, but your first solution fails and I figured out why. According the MDN documentation on arrow functions, "Arrow functions do not expose an arguments object to their code" so your arguments.callee does not exist and throws an error. – Patrick Roberts Sep 13 '15 at 17:47
• Interesting. For me in Firefox Developer Edition 42.0a2 (2015-09-13), both work. I guess once the standard is fully adopted the first one will stop working. – DankMemes Sep 13 '15 at 17:52
• I tested them on latest chrome since I was trying to golf your first solution with ! instead of enclosing parentheses and putting the function execution after the for loop to avoid the need for the for loop semicolon body which would save (I think) 4 bytes – Patrick Roberts Sep 13 '15 at 17:54

# Microscript, 22 bytes

"f1{CqxCanx"f1{CqxCanx


Based on the quine from the Esolangs article: "fCqxah"fCqxah. Exploits the fact that the language autoappends closing braces as needed, without which this would be two bytes longer.

## Batch, 10 (+ 4 for filename length)

Not sure if this qualifies for two reasons:

• Technically, there may or may not be textual side effects from the Windows command shell, as that depends on how it is configured.
• This program invokes itself by name, and I am not sure whether that's prohibited by the rules (specifically the "no opening of program file" rule). It is not opening itself for the purposes of reading and printing out the text; it is simply re-running itself. Further, the file system structure is an integral part of old-school batch scripts (oftentimes even being used to store program state, etc). As such, I am not sure whether this violates the 5th rule or not.

The code (for a program named q.bat):

echo on&&q

• I get I'll allow it since it's not the shortest, and it's creative and unique. And it wasn't reading the source code, but rather executing itself. – mbomb007 Sep 12 '15 at 3:37
• Since the file name is not arbitrary, at the very least you should add the file name to the byte count. – Martin Ender Sep 12 '15 at 5:40
• I believe you could use echo on&&%0 although I'm afraid to try it. – DankMemes Sep 12 '15 at 19:12
• Update: echo on&&%0 does not work. %0 is displayed as expanded in the output, and windows (7, 32 bit, running in a VM) terminates the entire thing pretty quickly. – DankMemes Sep 12 '15 at 19:50
• I think you can omit the .bat part – SuperJedi224 Sep 15 '15 at 19:01

# Ceylon, 210 208 bytes

Of course this won't win anything...

shared void u(){value q="\"\"\"";value t="""shared void u(){value q="\"\"\"";value t=""";value b="""while(1<2){print(t+q+t+q+";value b="+q+b+q+";"+b);}}""";while(1<2){print(t+q+t+q+";value b="+q+b+q+";"+b);}}


Original:

shared void u(){value q="\"\"\"";value t="""shared void u(){value q="\"\"\"";value t=""";value b="""while(true){print(t+q+t+q+";value b="+q+b+q+";"+b);}}""";while(true){print(t+q+t+q+";value b="+q+b+q+";"+b);}}

I modified my Quine from two days ago by adding the while(true){...} loop, so I come from the 185 bytes of the plain Quine to 210 (I don't need the trailing new line character anymore). But then I found that a while(1<2){...} loop is even two bytes shorter:

shared void u(){value q="\"\"\"";value t="""shared void u(){value q="\"\"\"";value t=""";value b="""while(1<2){print(t+q+t+q+";value b="+q+b+q+";"+b);}}""";while(1<2){print(t+q+t+q+";value b="+q+b+q+";"+b);}}

(Ceylon has no for(;;) loop like Java, and the braces are also needed for this loop.)

## PowerShell, 132 107 Bytes

$a='$a={0}{1}{0};for(){2}$a-f[char]39,$a,[char]123,[char]125{3}';for(){$a-f[char]39,$a,[char]123,[char]125}


Based off of the Rosetta Quine (Same as @AdmBorkBork) although doesn't use formatting for string replacement... maybe switching to a for loop and using formatting would be best?

I'm sure if AdmBorkBork came back they would beat this by a lot :P

EDIT Figured out the for loop and replacements, all thanks to my predecessor :)

Old attempt:

$a='$a=;for(){$a.substring(0,3)+[char]39+$a+[char]39+$a.substring(3)}';for(){$a.substring(0,3)+[char]39+$a+[char]39+$a.substring(3)}


# Ruby, 41 39 bytes

A modification of one of the Ruby quines found here.

_="_=%p;loop{puts _%%_}";loop{puts _%_}


# Java 10, 194 bytes

interface M{static void main(String[]a){for(var s="interface M{static void main(String[]a){for(var s=%c%s%1$c;;)System.out.println(s.format(s,34,s));}}";;)System.out.println(s.format(s,34,s));}}  Explanation: Try it online (times out after 60 sec). interface M{ // Class static void main(String[]a){ // Mandatory main-method for(var s="interface M{static void main(String[]a){for(var s=%c%s%1$c;;)System.out.println(s.format(s,34,s));}}";
//   Unformatted source code
;)                      //   Loop indefinitely
System.out.println(      //    Print with trailing new-line:
s.format(s,34,s));}}   //     The formatted source code


-part:

• The String s contains the unformatted source code.
• %s is used to input this String into itself with the s.format(...).
• %c, %1\$c and the 34 are used to format the double-quotes.
• s.format(s,34,s) puts it all together

Challenge part:

• for(;;) is used to loop indefinitely.
• System.out.println(...) is used to print with trailing new-line

# Funky, 29 bytes

f=@printf=[f]for)f()for)f()


Try it online!

# RProgN 2, 7 bytes

«]³]]p:


Try it online!

# Jelly, 14 bytes

“;@ṾṄṛ¢”;@ṾṄṛ¢


Try it online!

# Pyth, 11 bytes

#jN B"#jN B


Try it here!

• It works well enough. Just pause execution shortly after running. – mbomb007 Apr 17 '18 at 2:05
• Huh, nice! I'll edit that link in. – RK. Apr 17 '18 at 13:59

# Keg, 16 bytes

{④⑩9⑨,}{④⑩9⑨,}


Try it online!

Ties with most other golfing languages, so I'm happy with that. Pushes the string {④⑩9⑨,}, which is then infinitely printed rawly, then nicely followed by a newline infinitely.