146
\$\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
  • 141
    \$\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\$
    – Doorknob
    Nov 9, 2013 at 20:00
  • 27
    \$\begingroup\$ Does "infinite until your computer crashes" count? <_< \$\endgroup\$
    – Izkata
    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\$
    – DampeS8N
    Nov 12, 2013 at 20:27
  • 12
    \$\begingroup\$ @Izkata So any answer that crashes your computer is also allowed :D \$\endgroup\$ 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\$
    – Sanchises
    Apr 10, 2015 at 21:15

334 Answers 334

1
4 5
6
7 8
12
1
\$\begingroup\$

Self-modifying Brainfuck, 4 bytes

Prints ] forever. Note that the traditional BF programs work as well.

<[.]

The pointer starts one to the right of the source code on the tape, so moving left once puts the pointer at ].

\$\endgroup\$
1
\$\begingroup\$

Simplefunge, 3 chars

Does it count if, you know, it is your own language?

>o<

Prints 0 over and over again, as the tape is initialized as a tape of infinite zeros.

\$\endgroup\$
1
\$\begingroup\$

PlatyPar, 3 Bytes

1WA

Explanation:

1    ## push 1 to the stack
 W   ## while(stack[-1])
  A  ## alert(stack[-1])

Works the same as my truth machine, except manually inputting the 1 instead of asking for it.

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Detour, 1 bytes

,

Try it online!

, outputs its contents, and passes it on to the next cell (,). In the event of not being given input, a 0 will be passed in.

\$\endgroup\$
1
\$\begingroup\$

BASTARD 30 Bytes

{(., <> {fi out {t 0}(.)})(.)}

This makes use of a few things that are still in question with the spec, but I'm the authour, so what the hell.

Note: BASTARD is still under development, and I haven't finished the spec, or even a rough REPL, so it probably should be disqualified for everything.

Explanation:

  1. Everything has to sit in a {} block.
  2. We define a function called . that takes no arguments.
  3. The function prints an undefined variable from the stack, which equates to 'nil'.
  4. The function also calls itself, thus an infinite loop.
  5. We call the infinite function.

Note: Anonymous functions may or may not be introduced in the future. The current syntax proposed would reduce the above to 24 bytes:

{(<> {fi out {t 0}(@)})}

The only new concept here is @, which is a self-reference to the anonymous function.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ I suggest deleting this answer temporarily until you have released the language \$\endgroup\$ Mar 1, 2016 at 18:03
1
\$\begingroup\$

Reng v.1.2, 1 byte

Try it here!

n

Pops N and prints N. N is always zero, popping off the empty stack.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ If Reng is newer than this challenge, you should state that in your answer. \$\endgroup\$
    – Dennis
    Mar 21, 2016 at 3:39
1
\$\begingroup\$

Scratch, 3 bytes

Script
(scoring used)
Adds a blank item to list = repeatedly and indefinitely.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ I can't see your script because of a 503 error. I think that using the button to upload an image is better, since it uploads to i.stack.imgur.com. \$\endgroup\$ Oct 6, 2016 at 18:57
  • \$\begingroup\$ That's because CubeUpload is down at the moment. \$\endgroup\$ Oct 8, 2016 at 18:05
  • \$\begingroup\$ Well, can you posts the ScratchBlocks version of the script at least (golfed)? \$\endgroup\$ Oct 8, 2016 at 18:11
1
\$\begingroup\$

Burlesque - 2 Bytes

bc

basically just creates an infinite list and outputting infinite lists will obviously produce infinite output.

Don't try this in the online shell because some browsers freeze when trying to render the result because it's huge :) (at some point either the browser stops rendering or the webserver closes the stream).

\$\endgroup\$
1
\$\begingroup\$

Hexagony, 1 byte

This answer is non-competing, as Hexagony is newer than this challenge.

!

Try it online!

Prints an infinite amount of 0s by printing the value of the initial memory edge (which happens to be 0) over and over. The ! is executed in a loop because the source code is toroidal.

\$\endgroup\$
1
\$\begingroup\$

Woefully, 49 bytes (newer than challenge)

||| |
|| |
| |
|| |
||| |
|||| |
||||| |
|||||| |

Explanation

v     v represents char pointer, instruction pointer finds first space after the char
|||A|                                                      pointed at by char pointer
||A|  A- Push zero
|A|
||B|
|||B| B- Pop and print (number)
||||B|
|||||B|
||||||B|
    [end] End- go back to character char pointer is pointing at. Char pointer has not moved
so it will just execute the same again
\$\endgroup\$
1
\$\begingroup\$

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;

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Php is not that bad :) <?for(;;a); 11 chars \$\endgroup\$
    – tacone
    Nov 30, 2013 at 22:01
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – primo
    Feb 2, 2014 at 7:17
  • \$\begingroup\$ @primo I do lol \$\endgroup\$
    – Oliver Ni
    Aug 6, 2017 at 12:02
1
\$\begingroup\$

Sonic Pi, 19 Bytes

loop do puts "" end

Sonic Pi is a sound language, but it's also fully a programming language.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ What is sonic pi, for those who don't know? \$\endgroup\$
    – Riker
    May 6, 2016 at 15:33
1
\$\begingroup\$

zsh (8 chars)

</dev/z*

Analogous to cat /dev/zero.

Note: This does depend on there not being any other files in /dev starting with z, other than /dev/zero.

\$\endgroup\$
2
  • \$\begingroup\$ Given that this particular configuration of /dev is the default on many UNIX-like operating systems (e.g. Ubuntu, which I had easily available to test), I'm pretty sure there are "implementations" where this works. \$\endgroup\$
    – user62131
    Nov 26, 2016 at 21:36
  • \$\begingroup\$ You can just do </*/*, which includes at least /dev/zero so is therefore infinite. \$\endgroup\$
    – pxeger
    Apr 17, 2022 at 18:06
1
\$\begingroup\$

TI-83 Hex Assembly, 6 bytes

PROGRAM:I
:AsmPrgm
:EF0A45
:C3959D

Run with Asm(prgmI). Prints garbage over and over again. The only way to stop the printing is to physically remove the batteries from the calculator and re-insert them, at which point the calculator's RAM will be cleared. I count each hex digit pair as one byte.

\$\endgroup\$
1
\$\begingroup\$

Casio FX-7000G, 6 bytes

Lbl 0◢
Goto 0

This uses the calculator's own encoding, where each token is stored as a byte.

Lbl 0 sets the label of the first line to 0. The triangle means "print last value", which is in this case 0. The next line is your standard Goto statement, jumping back to the top so the value can be printed again.

Due to the calculator's limitations, the user must press EXE after each printed value before the next can be displayed.

\$\endgroup\$
1
  • \$\begingroup\$ Very cool. The FX-7000G was cutting-edge tech in the mid 80s. Reminds me of my old FX-3900P (RIP) \$\endgroup\$
    – roblogic
    Jul 29, 2019 at 10:20
1
\$\begingroup\$

Labyrinth, 1 byte

!

Labyrinth's stack has implicit zeroes at the bottom and the ! character outputs the integer representation of top of the stack. Since the program never finds anywhere else to go besides this single character, it keeps repeating that instruction.

\$\endgroup\$
1
\$\begingroup\$

GO, 13 bytes

for{print(0)}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

8th, 24 19 bytes

: f 0 . recurse ; f

The word f pushes a 0 on the stack and print it in a recursive way

\$\endgroup\$
2
  • \$\begingroup\$ Won't that fail with a "stackoverflow" ? (i.e. does 8th recognize the tail recursion?) \$\endgroup\$
    – zeppelin
    Jan 17, 2017 at 22:30
  • \$\begingroup\$ @zeppelin - 8th implements "tail-call elimination" and the above mentioned code runs smoothly. See this post for further explanation. \$\endgroup\$ Jan 18, 2017 at 6:45
1
\$\begingroup\$

Commodore Basic, 5 bytes

1?:R╭

PETSCII substitution: = SHIFT+U

Prints a newline, then runs itself. Forever.

\$\endgroup\$
1
\$\begingroup\$

SmileBASIC, 6 bytes

?EXEC.

? is print, EXEC runs a program, and . is the same as 0.0.

If newlines don't count as output, here's a 7 byte answer:

?.EXEC.

?. = PRINT 0.0, EXEC. = EXEC 0.0

\$\endgroup\$
1
\$\begingroup\$

Alice, 1 byte

o

Prints null bytes indefinitely.

\$\endgroup\$
1
\$\begingroup\$

Braingolf, 6 bytes

[1+!_]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Decimal, 12 bytes

11D91D30191D

Try it online!

Explanation:

11D   ; push whatever's in RAM to the stack as an INT
91D   ; declare jump 1
301   ; print
91D   ; goto jump 1

Another version that does not invoke undefined behavior:

82D   ; builtin - push random INT to stack
91D   ; declare jump 1
301   ; print
91D   ; goto jump 1
\$\endgroup\$
1
\$\begingroup\$

Check, 3 bytes (non-competing)

#<#

Outputs infinite newlines.

Check is my new esolang. It uses a combination of 2D and 1D semantics.

Explanation

This uses a bit of a hack in the language - namely, that < means "print a newline" in 1D mode, and "move left" in 2D mode.

The IP first runs into a #, which turns it into 2D mode. However, it runs into <, which immediately points it back. It runs into the first # again and switches back to 1D mode. The IP then hits <, which outputs a newline, and then hits the second #, which switches it back to 2D mode again. The IP wraps around to the first #, where it switches back to 1D mode. It hits < again, printing another newline, and the process repeats.

\$\endgroup\$
2
  • \$\begingroup\$ ...how is that 7 bytes? \$\endgroup\$
    – MD XF
    Jun 6, 2017 at 4:11
  • \$\begingroup\$ @MDXF I guess I awarded myself extra bytes for not being able to count. \$\endgroup\$ Jun 6, 2017 at 5:00
1
\$\begingroup\$

Unreadable, 16 bytes

'"""""'"""'"'"""

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Aren't Unreadable programs supposed to use the > '"""""'"""'"'""" markdown, to live up to its name? \$\endgroup\$ Dec 10, 2017 at 14:52
1
\$\begingroup\$

MOO, 39 38 bytes

while(!suspend(player:tell()))endwhile

Huge abuse of side effects; player:tell() by default does not return a value, which means it implicitly returns zero, and the resulting suspend(0) is necessary to avoid running out of ticks.

\$\endgroup\$
1
\$\begingroup\$

Cubically, 3 bytes

%0)

This should look like this:

(%0)
(    open loop that can always be jumped to
 %0   print 0th face sum as integer (0)
   ) jump back to loop regardless of faces

However, ) will just jump back to the start of the file if no jump point is provided.

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 20 bytes

for(;;)console.log()

Sends infinite undefined output.

\$\endgroup\$
1
\$\begingroup\$

VBScript, 23 characters

Do:Wscript.Echo"C":Loop

Needs to be run with cscript.exe for command-line output. If run with wscript.exe (default action), it opens infinite dialog boxes.


Also, here's a shorter (17 character) version which opens boxes regardless of whether it's running using cscript.exe or wscript.exe.

Do:MsgBox"C":Loop

However I'm not sure if that counts too, as it doesn't print anything and just opens dialog boxes indefinetely.

\$\endgroup\$
1
\$\begingroup\$

GW-Basic, 9 bytes (tokenised)

TRON:RUN

This will output [0] until the cows come home. Actually only 3 bytes are actual tokens; here's the full content of the file:

255      unprotected
xxx xxx  offset, recalculated on LOAD
0 0      line number 0
162      TRON
':'      :
138      RUN
0        line terminator

You can often delete trailing zeroes, but this one was required because when GW-Basic starts up, another value is at the memory location where that zero will get loaded, so without it you'd get a syntax error.

\$\endgroup\$
1
4 5
6
7 8
12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.