150
\$\begingroup\$

Write the shortest code you can that produces an infinite output.

That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code wins.

Here's a list of answers that I think are really clever, so they can get credit:

Leaderboard

var QUESTION_ID=13152,OVERRIDE_USER=8611;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
16
  • 144
    \$\begingroup\$ All answers disqualified because at some point the Earth will be swallowed by the sun, and at some point the universe will die :P \$\endgroup\$ Commented Nov 9, 2013 at 20:00
  • 29
    \$\begingroup\$ Does "infinite until your computer crashes" count? <_< \$\endgroup\$ Commented Nov 10, 2013 at 1:39
  • 7
    \$\begingroup\$ If I write mine in Piet, can I count the pixels of the text the other programs used? I believe the smallest possible repeating Piet program would be 6 pixels. That beats Befunge if "off" pixels still count. \$\endgroup\$ Commented Nov 12, 2013 at 20:27
  • 13
    \$\begingroup\$ @Izkata So any answer that crashes your computer is also allowed :D \$\endgroup\$ Commented Jul 11, 2014 at 20:11
  • 11
    \$\begingroup\$ @Doorknob So really, the challenge is to produce infinite output in a finite amount of time. Sounds easy enough. \$\endgroup\$ Commented Apr 10, 2015 at 21:15

349 Answers 349

1
8 9 10
11
12
0
\$\begingroup\$

Fission 2, 2 bytes

R" 

Try it online!

Same concept as the Befunge answer. An atom is spawned at the R, and moves right. It reaches the " and enters string mode, wraps to the beginning of the line and prints an R, then exits string mode and wraps again.

Outside of string mode, R simply changes the atom's direction to right, which is the direction it's already moving in.

\$\endgroup\$
0
\$\begingroup\$

Add++, 9 bytes

+1 W,+1,O 

Prints 1 Followed by a newline for ever.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

AHK, 11 bytes

Loop Send,a 

Pretty boring but couldn't find an AHK answer in here and thought it worthy of submission.

\$\endgroup\$
0
\$\begingroup\$

Bitwise, 19 bytes

OUT 0 &1 JMP &-2 &1 

Prints a load of null bytes. Try it online!

OUT 0 &1 prints the 0th register when a literal 1 is truthy. JMP &-2 &1 jumps back two (one) lines when a literal 1 is truthy.

\$\endgroup\$
0
\$\begingroup\$

Evil, 4 bytes

Continuously prints the Start of Heading character:

amwb 

If NUL is allowed you could do mwb.

An alternative, that goes through the ASCII characters, would be:

mawb 

Quick explanation of commands:

  • m = marking character;
  • a = increment accumulator;
  • w = write accumulator to STDOUT;
  • b = go backwards to marking character and continue execution from there.
\$\endgroup\$
0
\$\begingroup\$

J-uby, 11 Bytes

-:p|:+&1!~0 

Explanation

!~ is iterate until constant: x = f(x) until x == f(x)

-:p is the global print function, and :+&1 increments a number

So -:p|:+&1 prints a number and returns the next integer

We start at 0

\$\endgroup\$
0
\$\begingroup\$

VBA, 18 Bytes

Anonymous VBE immediate window that outputs an infinite quantity of newline characters vbCrLf to the VBE immediate window

Do:DoEvents:?:Loop 
\$\endgroup\$
0
\$\begingroup\$

QBIC, 3 2 bytes

{? 

Explanation:

{ Start a DO-loop ? PRINT nothing, followed by \n The DO-loop is implicitly closed by QBIC. 
\$\endgroup\$
0
\$\begingroup\$

R, 15 chars (or 6)

repeat print(1) 

or, you could cheat slightly with just

repeat 

which will invisibly return NULL for each time through the loop. Thus it will return NULL infinite times, you just can't tell.

\$\endgroup\$
0
\$\begingroup\$

Jq 1.5, 9 bytes

repeat(1) 

Try it online! (truncated at 128K)

\$\endgroup\$
0
\$\begingroup\$

cQuents 0, 1 byte

$ 

Try it online!

Outputs 1,2,3,4,5,6... up to Python's int cap (aka as long as you have memory).

Alternately, any number would work, printing that number separated by commas infinitely:

7 

Try it online!

This may work at some point with an empty program once I finish this language - theoretically it should print 0,0,0,0,0,0... for an empty program but I haven't implemented empty nodes.

\$\endgroup\$
0
\$\begingroup\$

Funky, 13 bytes

for()print(1) 

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Whispers, 28 bytes

> 1 >> Output 1 >> While 1 2 

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Aceto, 2 bytes

pO 
 p prints the top stack element (implicit 0) O returns to the origin of the program 

Try it online!

alternate version:

nO
n prints a newline, O returns to origin
\$\endgroup\$
0
\$\begingroup\$

Forked, 1 byte

% 

Prints the top of stack (0 if empty). The IP wraps upon hitting the edge of the playing field, looping infinitely.

\$\endgroup\$
0
\$\begingroup\$

Wumpus, 2 bytes

OO 

Try it online!

Outputs infinite 0s

Funnily enough, even though a single O causes an infinite loop, a new command is only executed once it leaves the current cell, meaning the pointer gets trapped inside the O triangle, bouncing off the walls. Adding another cell (which could be almost any cell that doesn't end the program such as @ or %) allows the pointer to escape and execute the Output instruction again.

\$\endgroup\$
0
\$\begingroup\$

Momema, 5 bytes

j0!j1 

Try it online! Outputs to STDERR. Requires the -d interpreter flag.

The Momema interpreter has a -d (debug) flag that enables a ! instruction, which outputs some debugging information to STDERR.

Explanation

j 0 # label j0: jump past label j0 (no-op) ! # debug j 1 # label j1: jump past label j0 (back to start) 
\$\endgroup\$
3
  • \$\begingroup\$ Remember, non-standard flags add to byte count by default \$\endgroup\$ Commented May 18, 2018 at 3:11
  • \$\begingroup\$ @Draconis Per a five-month old meta consensus they dont. \$\endgroup\$ Commented May 18, 2018 at 3:35
  • \$\begingroup\$ Ah, my bad! Apologies! \$\endgroup\$ Commented May 18, 2018 at 3:54
0
\$\begingroup\$

axo, 2 bytes

{_ 

Try it online!

 Implicit 0 on top of the stack { prints it _ returns to origin, or 0,0 
\$\endgroup\$
0
\$\begingroup\$

FALSE, 7 bytes

[^.^]3# 

This works in some FALSE interpreters (http://www.quirkster.com/iano/js/false-js.html (Paste the code, click "show", then click "step" a bunch of times (not "run" because it's an infinite loop!))). Outputs an infinite amount of -1s.

Explanation:

Some versions of FALSE are weakly typed, so a normal number can be used as a function pointer.

[^.^] pushes a function to the stack. (specifically, the character in the code that is starts at.) In this case, it pushes the number 0.

3 Pushes the number 3, which when called as a function will start execution at the ] of the previous function (meaning that it skips all the code)

# Is a "while" loop. It pops two functions, then calls the first function (that is, the one which was PUSHED first). It then pops a value from the stack, and if this value is true, it runs the second function and repeats. If the value is false, it continues.

Our function [^.^] will first use ^ to push the next character of STDIN (if input is empty, it pushes -1), then . prints the numerical value (-1), and ^ pushes the next value of input again. This is the value which will be "returned" and used in the loop. Because it is non-zero, the second "function" is called (which is just a number pointing to a location in the code), and the interpreter immediately sees a ], causing it to return from the function.

\$\endgroup\$
0
\$\begingroup\$

Stax, 3 bytes

W1P 

Run and debug it

Outputs 1 forever. Since Stax terminates when trying to peek or pop an empty stack, I am not sure how to do it in 2 bytes or less.

\$\endgroup\$
2
  • \$\begingroup\$ Since W1Q also works and differs in only the final bit, the first 23 bits of this work regardless of the 24th; could it be claimed that this is 2.875 bytes? Is this a dumb question? \$\endgroup\$ Commented Apr 6, 2018 at 11:21
  • \$\begingroup\$ Interesting idea, but I honestly don't know. Sadly W1Q will stack overflow after some time ... \$\endgroup\$ Commented Apr 7, 2018 at 0:30
0
\$\begingroup\$

ORK, 170 bytes

There is such a thing as a o A o can i When a o is to i: I have a scribe called W W is to write "!" I am to loop When this program starts: I have a o called O O is to i 

Try it online!

Objects R Kool. Maybe, but they're inconvenient (why can't I just loop the main function?).

\$\endgroup\$
0
\$\begingroup\$

Burlesque - 2 bytes

bc bc box cycle 

Rather boring. bc encloses the top of the stack in a block and then infinitely repeats this block and thus when the value is printed when the program stops it'll obviously never stop producing output.

\$\endgroup\$
0
\$\begingroup\$

MathGolf, 4 3 bytes

Äo↔ 

Try it online!

Explanation

Ä start block of length 1 o print TOS without popping ↔ do while false without popping 
\$\endgroup\$
0
\$\begingroup\$

JavaScript + HTML, 56 bytes

(g=_=>requestAnimationFrame(_=>document.writeln(g())))() 
\$\endgroup\$
0
\$\begingroup\$

Turing Machine But Way Worse, 13 bytes

0 0 1 1 0 1 0 

Try it online!

prints chr(128),chr(128+64),chr(128+64+32),...,chr(128+64+...+2+1) infinitely.

No explanation since the code is self-explanatory.

\$\endgroup\$
0
\$\begingroup\$

JVM bytecode (OpenJDK asmtools JASM), 194 bytes

enum i {public static Method main:"([Ljava/lang/String;)V" stack 2 locals 1 {l:getstatic java/lang/System.out:"Ljava/io/PrintStream;";ldc 0;invokevirtual java/io/PrintStream.print:(I)V;goto l;}} 

Ungolfed

enum i { public static Method main:"([Ljava/lang/String;)V" stack 2 locals 1 { l: getstatic java/lang/System.out:"Ljava/io/PrintStream;"; ldc 0; invokevirtual java/io/PrintStream.print:(I)V; goto l; } } 

First we get a reference to System.out, then we just invoke void print(int) with zero. Repeat until the heat death of the universe, since this method never returns.

Using enum instead of class saves 1 byte, along with using ldc 0 instead of iconst_0 to save 2 more bytes.

Bonus points for not decompiling correctly in the Fernflower decompiler, no?

\$\endgroup\$
0
\$\begingroup\$

Python: (16 characters)

while 1:print(0) 
\$\endgroup\$
5
  • 2
    \$\begingroup\$ I don't believe you need the parentheses around the 1. while 1:print(0) should work just fine. \$\endgroup\$ Commented Feb 14, 2019 at 20:30
  • \$\begingroup\$ You can also save a byte on the print by using python 2 \$\endgroup\$ Commented Feb 14, 2019 at 21:34
  • 1
    \$\begingroup\$ you don't even need the 0 since python prints a newline \$\endgroup\$ Commented Feb 14, 2019 at 22:11
  • \$\begingroup\$ You are right @Joking. New line is invisible output. \$\endgroup\$ Commented Feb 14, 2019 at 22:14
  • \$\begingroup\$ while 1:print() would print a newline \$\endgroup\$ Commented Mar 3, 2019 at 17:45
0
\$\begingroup\$

Tamsin, 15 bytes

main={print 1}. 

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Perl 6, 11 bytes

loop {.say} 

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Brian & Chuck, 8 bytes

!{? !{.? 

Try it online!

Brian simply restarts Chuck and Chuck sets Brian's instruction pointer to the left end, prints it and restarts Brian.

Produces endless "!!!!!!..."

\$\endgroup\$
1
8 9 10
11
12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.