# 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? <_< 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. Nov 12 '13 at 20:27
• @Izkata So any answer that crashes your computer is also allowed :D 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. Apr 10 '15 at 21:15

## R, 13 characters

repeat cat(1)

• repeat cat(1) should work Nov 9 '13 at 19:40
• @Dason you're right. I have no idea why i insist on putting them every time. Nov 11 '13 at 7:57

## PowerShell 2.0: 1711 8

My initial solution:

while(1 -eq 1){1}

Thanks to r.e.s.:

while(1){1}

I think Danko Durbić has the winner, here. I'm not even sure why this should work, but it does and I can't think of anything shorter so far.

for(){1}

• Try while(1){1}. Nov 12 '13 at 2:18
• @r.e.s. I was going to trim it by two with while($true){1} but your solution definitely wins - I forgot that in PowerShell $true -eq 1. Post that as an answer, and I'll give you a vote.
– Iszi
Nov 12 '13 at 2:21
• Feel free to edit it into yours, if you like. Nov 12 '13 at 2:35
• Try for(){1} . Nov 14 '13 at 13:22
• @DankoDurbić Can you explain why that works? I don't quite get it. Seems it should error to me.
– Iszi
Nov 14 '13 at 14:15

# Postscript 9

{1 =}loop


Output 1 in an infinite loop.

## C#, 57

Another C# entry, with a twist:

class M{static int Main(){for(;;)System.Console.Beep();}}


This interpretation of "output" may be stretching, but still valid I think (and saves 4 characters! :)

• Doesn't work on 64 bit Mar 4 '14 at 2:15
• @ColeJohnson Works fine for me: copy con test.cs, paste that string, ^Z and press Enter. csc /platform:x64 test.cs shows no errors. test.exe gives beep beep beep...
– Nick
Mar 4 '14 at 20:09
• I meant that the internal speaker won't work. You'll hear the beeps, but they're "artificial" beeps from your desktop speakers. Mar 7 '14 at 0:17
• @ColeJohnson Ah, that is true. Starting with Windows 7 64-bit the PC speaker driver (beep.sys) was changed to direct output to the sound card.
– Nick
Mar 7 '14 at 0:30

BASIC

10 PRINT "HELLO WORLD"
20 GOTO 10

• Gotta love the classics. Mar 21 '16 at 4:07
• Is it required to use 10 20 not 1 2?
– l4m2
Apr 2 '18 at 2:49
• need to print DURAN DURAN RULEZ!!1!! for proper 80s vibe :) Jul 29 '19 at 10:39

## Windows Batch File, 1 character

Create a file called a.bat containing:

a


When you execute this batch file, it executes itself. The Windows Command Prompt by default echos every command to the console, so the output resembles:

C:\>a

C:\>a

C:\>a

C:\>a


## Python, 17 13

while 1:print


Thanks to Ben and r.e.s.

• You can shorten it to 15 by not printing a string and removing the brackets in the while... while 1:print 1
– Ben
Nov 10 '13 at 21:03
• Or 13 characters: while 1:print produces "infinite output" composed of newlines. Nov 10 '13 at 21:40
• How about while 1:1 ? Apr 28 '14 at 18:18
• which @KaranGoel found below as well Apr 28 '14 at 18:23
• @Willem Absolutely wrong. Literals are not allowed by themselves on executed programs. Apr 12 '16 at 13:10

# C, 20 bytes (competing according to the challenge's creator)

Suppose the following code is contained in e.c:

int i;
#include"e.c"


In a machine with infinite system resources, GCC will create an infinitely big temporary file trying to resolve a recursive #inclusion.

Xojo, 18 12 chars

Again, please don't actually run this (same reason as the JavaScript answer):

do
Beep
loop


Never said the output couldn't be audio...

# Brachylog, 3 bytes

=w\


Try it online!

Not only does it print infinitely, this prints something much more interesting than most answers here: all integers.

### Explanation

=       Assign an integer value to the input ; since it is not constrained, it can take any
value in (-∞, +∞), meaning there is an infinite number of choice points
The way = is implemented makes it so that the order of choices it will try is:
0, 1, -1, 2, -2, 3, -3, …

w      Write that integer to STDOUT
\     False (i.e. go back to = and try the next integer choice point)


### sed 7 5 chars (version 4.2)

sed -e ':;p;b' <<<'Hello world!'


Unfortunely, this won't work anymore, from version 4.4 of GNU sed:

sed -e ':a;p;ba' <<<'Hello world!'

• sed (GNU sed) 4.4: -e expression #1, char 1: ":" lacks a label Oct 14 '17 at 12:24

# Microsoft Word Math AutoCorrect, 4 bytes

3. Repeat.

Note: the GUI doesn't show the $'s being generated as the GUI doesn't update until the operation halts, which it won't here. If you open up your Task Manager, you can see the memory usage going up to see that this is indeed what's happening. Sure, I could have made it produce more $s but the production rate would still just be O(1) per loop anyway, and I'd be spending precious bytes programming it. Oh, and I'm counting the $s as output. # Perl 6, 13 11 characters Using some nice Perl6 syntax for infinite lazy lists: .say for ^∞  The code will print all integers from 0 upto infinity or until RAM runs out to store single big integers, whichever comes first. • whichever comes first I think it's safe to say that RAM is infinite Mar 17 '19 at 22:27 ## Haskell, 18 chars a=1:a;main=print a  N.B.: No new line at end! • 17 bytes Apr 14 '19 at 4:09 Perl, 10 chars TIMTOWTDI: $ perl -nE 'say;redo' <input>   # 10 chars (1+8+1)
$perl -E 'say while+1' # 11 chars$ perl -E 'o:say;goto o'        # 12 chars
$perl -E 'for(;;){say}' # 12 chars$ cat inf.pl
warn;exec$^X,$0                 # 15 chars


If you have infinite RAM (maybe in the cloud ;-)

$perl -E 'sub o{say;&o}o' # 14 chars$ perl -E '&{*1=sub{say;&1}}'   # 17 chars, just kidding *gg*


# Matlab, 13

while 1
1
end


This prints

ans =

1


infinitely many times.

• While this should work, note that MATLAB gets very angry if you try. I tested it in R2020b and it just froze up before it displayed anything. Aug 16 at 0:00

# PHP - 171613 11 bytes

<?for(;;)echo O;


Oh well, I guess PHP can't ever always win... Thank you, m.buettner

Edit:

<?for(;;)0/0;


As it turns out, division by zero triggers a warning in php. So, even though the output it produces goes to STDERR, it's still infinite!

Edit 2:

for(;;)0/0;


(Run with php -r)

• Do you really need that 1 in there? Jul 3 '14 at 19:00
• Huh. Apparently I don't. Jul 3 '14 at 19:51
• You don´t need the tags either if you use -r. Apart from that, this can´t be done any shorter (yet). Jan 8 '17 at 16:54
• @Titus Or can it :) Thanks for pointing out this answer to me :D Jan 8 '17 at 19:09
• Wish I could upvote it again. :) Nice! You can still remove <?. Oh and if notices were in the default config ... _ or any letter instead of 0/0. Unfortunately they aren´t. Jan 8 '17 at 23:21

# Wolfram Language ( Mathematica ) 14 bytes 12 characters

Do[Echo@1,∞]

• Do these 12 characters not need 14 bytes? Sep 26 '17 at 8:27
• @JonathanFrech yes, thank you, I corrected it. Sep 26 '17 at 10:16

## APL, 7

{∇⎕←⍵}1


Defines a function which output its argument and call itself with the same argument, then call it once with argument 1

# Brainfuck, 8 bytes

+[[+.]+]


Assumes wrapping.

I'm aware that a solution was already posted by @cardboard_box - allthough his doesn't print any printable characters.

Shell, 16 Chars

cat /dev/urandom

• also grep -r / . for 12 bytes Jul 29 '19 at 10:36

show[1..]


Prints an infinite list of integers starting from 1, exploiting the lazy evaluation of Haskell.

# Piet, 3 codels

==> <== here it is ;)

Just to make it visible, the same at codel size 10:

This program bounces forward and backward, executing:

forward direction:

1
PSH (push on stack)
OUN (output number)


backward direction:

MUL (multiply)
POP (pop from stack)


The backward instructions are ignored because the stack is empty.

So, the program prints an infinite amount of 1’s in the console.

• I suggest you make this CW and/or suggest that others upvote captncraig's answer if you think it's good. Jun 14 '15 at 1:49

# Emotinomicon 18 bytes, 5 chars

😀⏪😀😨⏩


Explanation:

😀 - push 0 to the stack
⏪ - open loop
😀 - push 0 to the stack
😨 - pop top of the stack, and output it as a number
⏩ - end loop


As long as there's something on the stack, it's going to loop indefinitely

• Golfs two bytes, and saves precious RAM: ℹ⏪😨ℹ⏩. Oct 8 '16 at 18:27

# Desmos, 1 byte

x


Graphs y=x forever.

• Look, submitting Desmos answers is my job :P Good job anyway. Jun 1 '19 at 17:48

## GNU sed, 5 bytes

:;l;b


Any sed script requires input to start executing. With echo|sed ':;l;b', a line with a single $ character on it is printed continuously. # Java (JDK 10), 32 bytes a->{for(;;)System.out.print(1);}  Try it online! # Japt, 4 bytes i@Oo  Try it online! ### How it works Ui@Oo Ui Call every 10 milliseconds... @Oo the function that prints undefined.  Without input, U is initialized to zero, and 0 .i is the wrapper for setInterval JS function. According to its spec, the interval is low-capped at 10, so the target function is called every 10ms (approximately). Oo prints its arguments to output, and with no arguments, it prints undefined. The following is only correct with unbounded call stack (and therefore not a valid submission). When run on an actual browser, it overflows the stack in an instant. ## 3 bytes ßOo  Try it online! ß recursively calls the program. The whole source is translated to rp(O.o()) which first calls O.o() and then calls the program again. • Your second solution doesn't qualify. .a() doesn't create an endless loop, it simply runs for all integers up to 1e8. See the language source code. May 17 '18 at 8:05 • The 4 byte answer doesn't qualify either, it will reach the stack limits very quickly, according to this SO question in under 50k iterations on most browsers. May 17 '18 at 9:58 • The new 9 byte solution doesn't qualify either, once the array reaches the maximum size allowed by the spec, the runtime will throw and the execution will stop. In V8, for example, the error is Uncaught RangeError: Invalid array length. May 17 '18 at 10:09 • @Nit Do you mean any code that uses ß for infinite execution is invalid, including this and this? Or is it fine under "unbounded call stack" assumption? For the array limit, ECMA spec says "If len + argCount > 2**53‑1, throw a TypeError exception" for arr.push, so I agree that the 9-byte one isn't strictly correct. But then it only leaves the boring $while(1)\$ though... May 17 '18 at 23:59
• Where did you find the "unbounded call stack assumption"? I don't see it anywhere in the question. Nice work on that 4 byte solution, by the way. May 18 '18 at 7:17

# TeX, 14 12 bytes

\def~{x

~}~


Less infinite than the other solutions, though, as TeX writes its output to a file.

• A blank line inside the definition would still make a \par token with 2 bytes less :-) May 14 '19 at 17:55

# TeX, 11 bytes

The following results in an infinite amount of Undefined control sequence. errors (if run in batch mode no human interaction needed):

\def~{\[~}~


# TeX, 14 bytes

The following creates a PDF with infinite lines each containing a dot (theoretically that is, since the process never terminates, the file isn't finalized so not really created). I've stopped the process after more than 1000000 pages were output. At some point memory wouldn't suffice anymore for this.

\def~{.\par~}~