# 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

## 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 – Cole Johnson 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. – Cole Johnson 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. – Michael Stern 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 :) – roblogic Jul 29 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


# 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.

## 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}. – r.e.s. 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. – r.e.s. Nov 12 '13 at 2:35
• Try for(){1} . – Danko Durbić 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

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...

## 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. – r.e.s. Nov 10 '13 at 21:40
• How about while 1:1 ? – Willem Apr 28 '14 at 18:18
• which @KaranGoel found below as well – Willem Apr 28 '14 at 18:23
• @Willem Absolutely wrong. Literals are not allowed by themselves on executed programs. – Erik the Outgolfer Apr 12 '16 at 13:10

# 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 – Alexx Roche Oct 14 '17 at 12:24

# Z80Golf, 0 bytes

Try it online!

Surprisingly, this is an empty machine code program that produces infinite output.

### How it works

Z80Golf machine initializes all the memory and registers to zero, and then loads the code to address 0. But there's nothing to load, so the whole memory becomes a no-op program.

When the PC hits the address $8000 ($ indicates hex in Z80 assembly), putchar is simulated. It consists of printing the register a to stdout and a ret instruction. Initially the stack pointer sp is zero, and ret does pc <- [sp]; sp <- sp + 2. The whole memory is zeroed, so the ret always returns to the start of the program regardless of sp.

The conclusion is that an empty Z80Golf program is a program that infinitely prints null bytes.

# 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 – MilkyWay90 Mar 17 at 22:27

# Minecraft > 1.9 2 + 5 = 7 Bytes

Note that this version of this "language" was created after the question.

Surprisingly good for MineCraft. o-o

This is using this definition of MineCraft scoring.

The command say 1 put inside of a permanently active repeating command block. It will permanently output [@] 1 to the chat.

• I believe this is technically invalid, because it uses a version of the language from after the challenge :P – lirtosiast Nov 12 '15 at 22:40
• Never mind. I'll mark it as invalid. ;D – Addison Crump Nov 12 '15 at 22:43
• It's valid now; we had a rule change. – wizzwizz4 Jul 31 at 12:46

a=1:a;main=print a


N.B.: No new line at end!

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

# 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. – Nit 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. – Nit 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. – Nit 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... – Bubbler 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. – Nit 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 :-) – Phelype Oleinik May 14 at 17:55

# TCL (15)

while 1 puts\ x


(kind'a silly that we must write at least 30 characters per reply :)

• Just improved it a bit. Ignore the "always brace your expr" and other rules in code golf ;) (I forgot that I could edit without approval) – Johannes Kuhn Nov 10 '13 at 22:49
• And if you use the interactive command line (tclsh), you could do w 1 pu\ x – Johannes Kuhn Nov 10 '13 at 22:55
• @JohannesKuhn Nice! Tks. – Rolazaro Azeveires Nov 11 '13 at 0:36
• Indeed, a character minimum on a code golf site is a bit odd even though it's standard across other SE sites. I usually pad with &nbsp; when necessary - though it rarely is for me, since I usually add an explanation of my scripts as well. – Iszi Nov 14 '13 at 17:50

## F# - 22

while 1=1 do printf"x"


## APL, 7

{∇⎕←⍵}1


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

PowerShell (8)

Save "a.ps1" file with following script code:

1
.\a.ps1


from command line run the script.

My initial solution was different, but I found that it has already been answered by Iszi.

I managed to write another solution with same byte length.

## protected by Community♦Jun 5 '18 at 8:05

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).