121
\$\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\$
  • 118
    \$\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 '13 at 20:00
  • 17
    \$\begingroup\$ Does "infinite until your computer crashes" count? <_< \$\endgroup\$ – Izkata Nov 10 '13 at 1:39
  • 5
    \$\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 '13 at 20:27
  • 9
    \$\begingroup\$ @Izkata So any answer that crashes your computer is also allowed :D \$\endgroup\$ – ɐɔıʇǝɥʇuʎs Jul 11 '14 at 20:11
  • 7
    \$\begingroup\$ @Doorknob So really, the challenge is to produce infinite output in a finite amount of time. Sounds easy enough. \$\endgroup\$ – Sanchises Apr 10 '15 at 21:15

269 Answers 269

2
\$\begingroup\$

Zozotez LISP: 7

When started with the minimal interactive session dictated in the documentation:

(:'r p)

How it works is that it redefined read so the REPL prints what print returns rather than keyboard input. The never ending output is continious lines of: Zozotez-moi~>NILNIL

When started with the full interactive session it gets longer, but does the same (10 bytes):

(:'read p)

Without a bootstrap Zozotez does just (eval(read)) thus we need to implement a loop in one expression (16 bytes):

((:'z(\()(p)(z))))

The : is set to it binds z to the lambda expression (\()(p)(z)), when called without arguments calls print (p) with default argument NIL, then calls z (recurses).

: returns the value (the function) so wrapping it all in parenthesis makes the initial call.

Common Lisp: 15

(loop(print())) ; prints infinite lines of NIL

Racket: 21

(let z()(print'N)(z))

Works similar. The names let makes and calls the proecdure l that takes no arguments. The body prints N, then recurses. print without arguments displays data quoted so it prints 'N'N'N....

Scheme: 23

(let z()(display'N)(z))

Same as Racket version only that display is used which don't quote output. NNNN...

\$\endgroup\$
2
\$\begingroup\$

awk, 15/19 chars

Canonical version, 19 characters:

BEGIN{for(;;)print}

Version requiring user input (one newline will do), 14 chars (scores as 15 because of the required input):

{for(;;)print}
\$\endgroup\$
2
\$\begingroup\$

Thue, 19

b::=~1
a::=ba
::=
a

The code prints an infinite stream of 1's.

The code is quite simple and easy to understand.

  • b can be expanded as "output 1" (then b is replaced with empty string)
  • a can be expanded as/replaced by ba
  • ::= on its own ends the list of rules
  • a on the last line represents the initial state.
\$\endgroup\$
2
\$\begingroup\$

Brainfuck - 6/4

Brainfuck does this easily:

-[.>-]

If we assume that the interpreter didn't zero the cells on startup but instead gave us already-initialised cells, the count goes down by two:

[.>]
\$\endgroup\$
  • 2
    \$\begingroup\$ Why not just -[.]? \$\endgroup\$ – Justin Apr 23 '14 at 18:51
  • \$\begingroup\$ Hm, I haven't thought of that really, good idea. \$\endgroup\$ – Darkgamma Apr 24 '14 at 13:34
  • \$\begingroup\$ But that is actually a duplicate of another answer here. \$\endgroup\$ – Justin Apr 24 '14 at 17:32
  • \$\begingroup\$ I haven't seen the others before now, really, though even just -[.] is shorter than the other answers given. \$\endgroup\$ – Darkgamma Apr 25 '14 at 12:06
  • \$\begingroup\$ You should really go through other answers, especially of the same language, before posting. \$\endgroup\$ – Justin Apr 25 '14 at 15:19
2
\$\begingroup\$

Bash, 9 characters

echo 1;$0

Because the $0 variable always holds the filename.

\$\endgroup\$
  • 1
    \$\begingroup\$ I'm not sure this will really have an infinite output. You'll run out of memory before reaching infinity. echo 1;exec $0 would be better (but also has more characters). \$\endgroup\$ – gniourf_gniourf Apr 26 '14 at 9:22
2
\$\begingroup\$

C# (16)

Directly executable in LinqPad:

for(;;)0.Dump();
\$\endgroup\$
2
\$\begingroup\$

Ruby: 9 charecters

loop{p 1}

p 1 is equivalent to puts 1.inspect

\$\endgroup\$
2
\$\begingroup\$

Mathematica, 11 bytes (invisible) or 17 bytes (visible)

Clearly not going to win here, but it works

For[,0<1,1]

If you actually want to see the characters streaming down the screen, use

For[,0<1,Print@1]

(20 bytes). I had thought I might do well with

Range@∞

or even

1~Table~{∞}

But to my surprise, the Kernel checks for infinite bounds and disallows them.

\$\endgroup\$
  • 2
    \$\begingroup\$ You'll definitely need the Print version. But that can be golfed further: 1>0 is shorter than True, Print@1 is shorter than Print[1] and you can leave out one of the two consecutive commas to use the 3-argument version of For. \$\endgroup\$ – Martin Ender Sep 2 '14 at 14:41
  • 1
    \$\begingroup\$ Echo@1 is shorter than Print@1. \$\endgroup\$ – Roman Jul 23 at 13:01
2
\$\begingroup\$

Shell, 16 Chars

cat /dev/urandom
\$\endgroup\$
  • 1
    \$\begingroup\$ also grep -r / . for 12 bytes \$\endgroup\$ – roblogic Jul 29 at 10:36
2
\$\begingroup\$

Pyth, 2

#G

(or # followed by any normal variable, actually).

# is while True. Variables are printed implicitly, and since G is 'abcdefghijklmnopqrstuvwxyz', that gets printed infinitely.

\$\endgroup\$
  • \$\begingroup\$ This makes me want to learn Pyth myself. \$\endgroup\$ – DJgamer98 Nov 13 '15 at 8:33
2
\$\begingroup\$

x86 machine code, 6 bytes

b40e cd10 ebfc

Assembly version of the code:

mov ah, 0Eh;    bios teletype output
code_golf:
int 10h;        print character(ascii 0)
jmp code_golf;  loop

This code constantly prints ASCII 0 (NULL).

This was run using DOSBOX

\$\endgroup\$
  • \$\begingroup\$ What OS is this for? (DOS? Linux?) Can you put that in your answer? \$\endgroup\$ – tbodt Mar 5 '15 at 22:24
  • \$\begingroup\$ @tbodt I did specify: x86. But, I can see how some people might be confused so I included how I ran the code. \$\endgroup\$ – SirPython Mar 5 '15 at 23:14
2
\$\begingroup\$

Piet (135 codels/pixels)

Prints an infinite sequence of $ signs (arbitrary, could've been anything. Loaded in the upper right corner of course).

The awesome program

Run with npiet -v11 the.gif

\$\endgroup\$
  • 2
    \$\begingroup\$ In Piet, pixels count as characters. \$\endgroup\$ – tbodt Feb 2 '14 at 23:40
  • \$\begingroup\$ @tbodt - It's 135 pixels, but 112 bytes (if I'm not mistaken) -- byte-count is supposed to be the code-golf criterion. \$\endgroup\$ – r.e.s. Feb 3 '14 at 0:24
  • 3
    \$\begingroup\$ what if you save it in a different image format? for piet, I count number of pixels. \$\endgroup\$ – tbodt Feb 3 '14 at 0:26
2
\$\begingroup\$

Jelly, non-competing

2 bytes This answer is non-competing, since the challenge predates the creation of Jelly.

Ȯß

Try it online!

How it works

Ȯß  Main link. Implicit argument: 0

Ȯ   Output/print the implicit argument.
 ß  Recursively call the main link.
    Thanks to tail call optimization, this results in an actual infinite loop.
\$\endgroup\$
2
\$\begingroup\$

APL, 6 4 bytes

→⍞←1

A traditional style APL function, so even works on all legacy APLs.

\$\endgroup\$
2
\$\begingroup\$

Desmos, 1 byte

x

Graphs y=x forever.

\$\endgroup\$
  • \$\begingroup\$ Look, submitting Desmos answers is my job :P Good job anyway. \$\endgroup\$ – Benjamin Urquhart Jun 1 at 17:48
2
\$\begingroup\$

APL, 4 bytes

1
→1

This code must be put in a function, since the →(goto) operator has only sense in a function.

\$\endgroup\$
2
\$\begingroup\$

Oration, 21 bytes (non competing)

to iterate, 1
listen,

40 bytes:

to iterate, 1
listen,
capture,
that's it

The first does print() (but it's python 2, so prints infinite ()), the second does print('') (the capture begins a string and the that's it ends it).

\$\endgroup\$
2
\$\begingroup\$

Sesos, 2 bytes (non-competing)

0000000: 2c06                                              ,.

Prints an infinite amount of ones.

Try it online! Check Debug to see the generated binary code.

How it works

The binary file above has been generated by assembling the following SASM code.

set numout ; Switch to numeric output

add 1      ; Set the current cell to 1.
jmp        ; Jump to the corresponding exit marker.
    put    ; Print the integer in the current cell to STDOUT.
           ; (implicit jnz)
           ;     If the integer in the current cell is non-zero,
           ;     jump to the previous instruction.
\$\endgroup\$
2
\$\begingroup\$

Retina, 4 bytes (non-competing)

The language is newer than the challenge.

+:`0

Try it online

Doesn't match, so output 0, then it does match so output 1, now it doesn't so output 0, etc...

\$\endgroup\$
  • 2
    \$\begingroup\$ A paradox in action :) \$\endgroup\$ – ETHproductions Nov 15 '16 at 23:05
2
\$\begingroup\$

Cubix, 2 bytes

.O

Test it online!

Cubix is a stack-based 2D language, created by me in March 2016. Cubix differs from ordinary 2D languages in that it's not strictly 2D: the code is wrapped around a cube. This program wraps to this cube net:

   .
>O . . .
   .

where the IP (instruction pointer) starts at the arrow. O outputs the item on top of the stack as a number; if the stack is empty, it outputs 0. . is a no-op.

When the IP reaches the right side of the cube net, it simply wraps back around to the left and runs O again. Thus, this code outputs 0 forever.

\$\endgroup\$
2
\$\begingroup\$

Commodore Basic, 5 bytes

1?:R╭

PETSCII substitution: = SHIFT+U

Prints a newline, then runs itself. Forever.

\$\endgroup\$
2
\$\begingroup\$

Emojicode, 41 bytes

🏁🍇🔁👍🍇😀🔤.🔤🍉🍉
\$\endgroup\$
2
\$\begingroup\$

I've got two:

C - 27 26 24 bytes

main(){for(;;)puts("");}

This one infinitely prints \n, due to the behavior of puts(3)

Brainfuck - 13 4 bytes

+[.]

This one infinitely prints the invisible Start Of Heading control character.


(Thanks to scottinet, Sylwester and Erik the Golfer for suggestions that helped shorten the answer)

\$\endgroup\$
  • \$\begingroup\$ I have something shorter. \$\endgroup\$ – tbodt Jan 30 '14 at 20:22
  • \$\begingroup\$ @tbodt Oh, I didn't know null counted. I thought it had to be visible \$\endgroup\$ – Braden Best Jan 30 '14 at 20:33
  • 3
    \$\begingroup\$ @B1KMusic, If you have 2 (or more) answers, it's best to post them separately. \$\endgroup\$ – gnibbler Feb 2 '14 at 9:38
  • \$\begingroup\$ The BF answer is already posted. \$\endgroup\$ – NoOneIsHere Nov 25 '16 at 3:23
  • 1
    \$\begingroup\$ Use puts("") for -2 bytes (prints \n infinitely) \$\endgroup\$ – scottinet Sep 1 '17 at 18:46
2
\$\begingroup\$

Chip-8, 5 bytes

Sound output counts, right?

0x6F 0xFF 'set register 15 to 255
0xFF 0x18 'set sound timer to the value of register 15
0x12      'jump to first instruction (second byte is 00 so it can be omitted)

If drawing graphics counts, 3 bytes:

0xD0 0x0F 0x12
\$\endgroup\$
2
\$\begingroup\$

Shakespeare Programming Language, 116 bytes

.
Puck, a pig.
Page,.
Act I:.
Scene I:.
[Enter Puck and Page]
Page:
Open thy heart! Let us return to act I.
[Exeunt]

Will output -1 forever.

\$\endgroup\$
  • \$\begingroup\$ What interpreter are you using? This doesn't seem to work on the official one. (nvm, found it) \$\endgroup\$ – Jo King Aug 27 '18 at 7:38
2
\$\begingroup\$

TI-Basic, 5

Pause

It does produce infinite output; in the top right hand corner, the pixels are alternating ;)

Game Maker Language, 11

while(1){a}

The a produces errors infinitely ;)

\$\endgroup\$
  • 5
    \$\begingroup\$ Well, the "Pause" token in TI-Basic (z80, at least), is actually 1-byte in memory :) (see tibasicdev.wikidot.com/pause) \$\endgroup\$ – Adriweb Sep 2 '14 at 19:11
  • 8
    \$\begingroup\$ Submitting the TI-BASIC entry is like saying any zero-character command-line entry counts because the cursor is blinking. \$\endgroup\$ – lirtosiast Jun 14 '15 at 2:12
  • \$\begingroup\$ The last one is bad. The code itself doesn't run for infinite times, but it's called infinite times \$\endgroup\$ – l4m2 Apr 2 '18 at 2:45
  • \$\begingroup\$ @l4m2 Good point, I'll take that one out. \$\endgroup\$ – Timtech Apr 2 '18 at 14:18
  • 1
    \$\begingroup\$ This should be two answers. \$\endgroup\$ – 12Me21 Jun 5 '18 at 13:40
2
\$\begingroup\$

HTML + JavaScript, 35 bytes

This alerts repeatedly. For some reason, it alerts 8. It also produces a 404 error in the console each iteration.

<img onerror=alert(this.src=x) src=

JSFiddle


This is 32 bytes, but is far less interesting:

<img onerror=for(;;)alert() src=
\$\endgroup\$
2
\$\begingroup\$

Alchemist, 10 bytes

_->_+Out_a

Try it online!

Explanation

Initially the universe contains the _-atom, there is only one reaction consuming _ and creating a new _ with the side-effect of printing a. This will go on until the real universe terminates.

\$\endgroup\$
2
\$\begingroup\$

Lean Mean Bean Machine, 5 bytes

O
$
~

Try it online!

Endlessly output 0

O spawns a marble, which drops and runs the operation there each tick. New marbles have a value of 0.
$ prints the marble's value.
~ teleports the marble to the top of the current column.

\$\endgroup\$
2
\$\begingroup\$

The Hexadecimal Stacking Pseudo-Assembly Language (24):

000000
400000
120000
010000

Continuously prints 0s.

\$\endgroup\$
  • 1
    \$\begingroup\$ Now that's a long language name \$\endgroup\$ – Benjamin Urquhart Jun 1 at 17:47

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

Would you like to answer one of these unanswered questions instead?

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