# Shortest code to produce infinite output

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:

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>

• All answers disqualified because at some point the Earth will be swallowed by the sun, and at some point the universe will die :P – Doorknob Nov 9 '13 at 20:00
• Does "infinite until your computer crashes" count? <_< – Izkata Nov 10 '13 at 1:39
• 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. – DampeS8N Nov 12 '13 at 20:27
• @Izkata So any answer that crashes your computer is also allowed :D – ɐɔıʇǝɥʇuʎs Jul 11 '14 at 20:11
• @Doorknob So really, the challenge is to produce infinite output in a finite amount of time. Sounds easy enough. – Sanchises Apr 10 '15 at 21:15

## Clojure - 18 15 chars

(while 1(pr 1))


## CoffeeScript, 14

Pretty unoriginal and similar to JavaScript:

alert 6while 1

• There is a loop keyword, this could be shortened down to loop alert 1 – eosterberg Apr 11 '15 at 16:03

PHP: 22 chars

<?PHP while(true){print(0);} ?>


My first golf, hope I did it right :)
It will hang your browser if you do it on a PHP page, but from the command line it does the expected: prints something until you get bored and stop it.

• Because you this is php, you can just put while(true){print(0);} the <?php ... ?> isn't actually php anyway – addison Sep 1 '14 at 23:43
• And the php portion of your answer, while(true){print(0);}, is actually 22 characters. – addison Sep 1 '14 at 23:45

## Chinese, 2 bytes

谕


Prints ÿ continuously.

• Isn't that two bytes? – John Dvorak Jan 29 '14 at 15:54
• @JanDvorak He didn't specify chars or bytes, and chars is default. – Timtech Jan 29 '14 at 16:08
• @Timtech According to the code-golf tag: If you use Unicode, byte count should use UTF-8. – Sylwester Jan 29 '14 at 22:14
• @Sylwester Okay – Timtech Jan 29 '14 at 23:07

I haven't seen Thue used here much, so here we go:

# Thue (22 19 bytes)

a::=ab
b::=~1
::=
a


# Cardinal, 3 characters

.%$ Explanation: . print active value % start pointers here$  jump to x,y = active, inactive value

.%$Pointers spread out in all cardinal directions from every % All pointers carry two values, initialized to 0. The upper value is called the active value, and it can be accessed directly. The lower value is called inactive value. Inactive values can only be accessed by flipping both values, switching the active to inactive, and the inactive to active, or by using instructions like$ that grab the
inactive value directly to e.g. execute a jump.
The < and > below the values are the positional and directional
markers of the pointers. In programs, they instruct pointers to change
the movement direction.

0 0     At this step, the first active value (from the left pointer)
0 0     gets printed in the console, the right pointer is going to

0      The jumped (former left) pointer prints out the next 0
0
>%$0 0 ... travels on ... .>$

0
0
.%>    ... reaches the jump instruction again, going to jump to 0,0 again

0
0
>%$... print out the next 0... and so on, to infinity.  http://esolangs.org/wiki/Cardinal # Bat, 2 chars %0  The output is (starting from a blank line, I've added nbsp to make it visible bellow)  d:\Temp\Supertemp>"D:\Temp\Supertemp\inf.bat" d:\Temp\Supertemp>"D:\Temp\Supertemp\inf.bat" d:\Temp\Supertemp>"D:\Temp\Supertemp\inf.bat" d:\Temp\Supertemp>"D:\Temp\Supertemp\inf.bat" d:\Temp\Supertemp>"D:\Temp\Supertemp\inf.bat" d:\Temp\Supertemp>"D:\Temp\Supertemp\inf.bat"  • This is dependent to where you have stored the file, but it will always output. This is an example output. – Erik the Outgolfer Oct 6 '16 at 19:02 • @EriktheGolfer, yes. – Qwertiy Oct 6 '16 at 21:34 # ><> Fish - 2 characters, I'm counting the shortest one. Thijs beat me to it, but oh well. Here are a couple more ><> answers. 1n -Infinite 1's, 2 bytes  >"drlow ,olleH"l ? ! ^ < o  -Infinite "Hello, world", 84 bytes. Edit: Whoops. It's character count, not bytecount. I also fixed the first answer. Edit 2: Thanks mbomb007 for shaving off 1 character. • Why not just use 1n? – mbomb007 Oct 15 '15 at 15:46 • @mbomb007 Whoops, forgot that I could do that. – SjoerdPennings Oct 15 '15 at 15:49 • "n also works. – mbomb007 Oct 15 '15 at 16:01 # GoLunar, 4 bytes This is the equivalent of 5543 zeros in a row in Unary, which is equivalent to +[.] in BrainF***. 5543  # BotEngine, 1x3=3 Noncompeting as BotEngine is much too recent a language. Anyway, here we go: >CT  It starts with a right-moving bot on the >. When it reaches the C, it creates a left-moving bot (which starts on the C.) On the next step, the left-moving bot reaches the > and is turned around to move right and the right-moving bot reaches the T, destroying itself and printing TRUE. The step after that, the other bot gets to the C starting the process over again. >CF also works but prints FALSE instead of TRUE. Using P in this case would print empty lines instead. # Javascript ES6, 28 bytes setIntervalconsole.log()  I didn't want to code an infinite for loop like everyone else... Try it here using anything BUT Firefox. # Mouse-2002, 3 bytes (0!)  prints 0 forever. Alternatively, for a more interesting and (theoretically) infinite error with no loop, the Ackermann Function in 99 bytes in this language: "M>"?a:"N>"?b:#Y,a.b.;$Y1%n:2%m:m.0=k:n.0=j:j.k.>[n.1+!|j.k.<[#Y,m.1-,1;!|#Y,m.1-,#Y,n.,n.1-;;!]]]@


Expanded:

"M>" ? a:
"N>" ? b:

1 a:
1 b:

#Y, a. b.;!

$Y 1% n: 2% m: ~ ack m. 0 = k: ~ store whether m == 0 in k n. 0 = j: j. k. > [ ~ if y>x n.1+ ~ print it | j. k. < [ ~ if x>y #Y, m. 1-, 1; | #Y, m. 1-, #Y, m.,n. 1-;;! ] ] ] @$


Errors recursively, forever, as long as the input was a positive nonzero integer. (result of a bug in the interpreter: the code is correct!)

# 𝔼𝕊𝕄𝕚𝕟, 4 chars / 7 bytes

↻ô1;


Try it here (Firefox only).

Translates to while(output(1)); in JS.

• output isn't a JS function... – mbomb007 Apr 26 '18 at 14:07
• There isn't really an equivalent to that function in JS, I guess I made it a placeholder name for the custom output function that ESMin uses. – Mama Fun Roll Apr 30 '18 at 14:11
• console.log would work – mbomb007 Apr 30 '18 at 14:51
• The function doesn't output by lines, but rather appends to output... Perhaps it's more like a process.stdout.write. – Mama Fun Roll Apr 30 '18 at 20:08

## C, 25 bytes

main(){while(puts("1"));}


## R, 15 bytes

Infinitely prints 1

while(T)cat(1)


# Pyth, 4 bytes (Non-competing)

Pyth is a new programming lenguage, so this answer doesn't count.

.V"0

Explanation:
.V   - Forever loop
"0 - Outputs zeros

• You should add a note to your title saying this is non-competing because the language is newer than the question. Also this can be golfed to #0 – Blue Feb 20 '16 at 12:56

# ForceLang, 23 bytes

label l
io.write goto l


Looks weird, but it works. The key here is that goto does not interrupt the evaluation of the current line, and returns nil.

# Pylons, 5

wp,1}


While 1, print the (empty) stack.

# Come Here, 21 bytes

COME FROM1 1TELL1NEXT


In the reference implementation, this prints infinitely many smiley characters. Don't ask me why.

• The smiley characters are printed because you are using Windows cmd. – Erik the Outgolfer Oct 6 '16 at 18:58

## Clojure, 14 bytes

(pr(cycle[1]))


## Brainfuck, 26 bytes

++++[>++++<-]>[>++<-]>+[.]


Do 4*4*2+1 (33, !) and the final loop is a infinite loop that only print the current memory cell (!).

• You could as well do +[.] (SOH), but then it would be a dupe. – Erik the Outgolfer Oct 8 '16 at 18:12

# Haystack, 6 bytes (non-competing, the language came 2 years after the challenge)

>"a"o<


This will print a [infinity] times.

If the above code gives a syntax error because of the lack of | (that character is the needle. The ultimate goal of all Haystack programs is to find the needle in the haystack), one can simply append it to the end:

>"a"o<|


# Golfscript - 7

{1a}:a~


I'm still learing golfscript, but unless I'm mistaken, this puts 1 on the stack, then starts over?

But apparently, the stack only prints when the program terminates, so perhaps this is better:

{1.p}do


(thanks Dennis)

• You need a space between 1 and a, otherwise it's a single variable. I suggest using a non-alnum as a variable name {1?}:?+. Also, this doesn't print anything. – John Dvorak Mar 4 '14 at 5:31
• This won't work, it will just print a stack level too deep error. Also, the stack is printed when the program finishes, so you have to print explicitly. Example: {1.p}do (7 bytes) @JanDvorak: [A-Za-z]+[0-9]+ is a single token, but [0-9]+[A-Za-z]+ is not. – Dennis Jun 21 '14 at 18:46
• I would downvote, but my vote is locked in. Help me out! – tbodt Sep 3 '14 at 21:54
• Edited as per @Dennis – McKay Sep 7 '16 at 21:42

## PHP, 9 chars

for(;;)a;


Assumes error_reporting includes notices, and you can run it like this:

php -r "for(;;)a;"


The output is the following (repeated until the script is stopped):

PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP Notice:  Use of undefined constant a - assumed 'a' in Command line code on line 1


Note: 11 characters if code is written in a file: <?for(;;)a;

• Php is not that bad :) <?for(;;a); 11 chars – tacone Nov 30 '13 at 22:01
• This assumes not only that E_NOTICE is enabled, but also that display_errors is set to STDOUT - no one in their right mind does this. – primo Feb 2 '14 at 7:17
• @primo I do lol – Oliver Ni Aug 6 '17 at 12:02

# Kitanai, 24 bytes

#print"0"&2&1#print"1"&~


The "#" defines a flag, the first "print" displays 0, then the "&2" jumps to the second "#", it then prints "1", goes to the origin ("&~") which is just after "&2", then it jumps to the first "#" thanks to the "&1". And it does all that infinitely :)

# FALSE, 8 bytes

Interpreter.

There are many programs that work, each 8 bytes. The one I find the most interesting is:

[1$][.]#  This is a while loop (#). [1$] is the condition, and it pushes two 1s. The last is popped for the condition (true), and then [.] is executed, which prints the number.

Here are some other programs (including the above):

[1$][.]# [1][1.]# [1$.][]#
[^^.][]#
[^.^][]#
[^][^.]#


A more interesting 9-byte (arbitrary 1-char repeated):

['c$,][]#  I feel that the following 7-byte programs should work on some FALSE interpreters, but I haven't found any such yet: [1"][]# [.1][]#  # Haxe, 19 bytes while(1>0)trace(1);  There are several things about Haxe that make this challenge more difficult than in similar languages: 1. Its lack of a for(;;) loop 2. Its unwillingness to consider anything other than true or false truthy or falsy 3. Its unwillingness to print an empty line (with trace();) If not for these things, this program might have been 15 bytes: for(;;)trace();  Test it online here, though you may not want to, as it freezes your browser. # Pushy, 3 bytes (Non-competing as language post-dates challenge) 3[_  Explanation: 3 \ pushes 3 to the stack [ \ starts an infinite loop _ \ prints out the contents of the stack  • [" Infinitely prints newlines (and you need to mark this answer as non-competing) – FlipTack Jan 22 '17 at 15:55 # C++, 23 bytes main(){for(;;)puts(";");}  I was too lazy, but hey, It outputs a javascript script, which does absolutely nothing! • This submission is neither a full program nor a function and thus is invalid (since snippets are disallowed). – user41805 Jan 23 '17 at 16:36 • Now with FULL program! – Matthew Roh Jan 23 '17 at 23:40 # QC 6 bytes Not competing because language is newer than the question A00$00

A00 prints nothing(because memory is empty) and a new line
\$00 jump to start(no recursion, sets instruction pointer to 00)