134
\$\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
  • 132
    \$\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
  • 21
    \$\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\$ Jul 11 '14 at 20:11
  • 8
    \$\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

306 Answers 306

1 2 3
4
5
11
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\$
8
  • \$\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\$ 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\$ 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\$
1
  • \$\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
  • 7
    \$\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
  • 10
    \$\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
  • 2
    \$\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\$

Shakespeare Programming Language, 89 bytes

,.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]Scene V:.Ajax:Speak thy!Let usScene V!

Try it online!

I haven't used this language before, this is mostly based on tips from "Tips for golfing in The Shakespeare Programming Language", so I think it can be made shorter.

\$\endgroup\$
1
  • \$\begingroup\$ You can reduce this to one Scene for 86 bytes \$\endgroup\$
    – Jo King
    Aug 27 '18 at 7:34
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\$

TI-BASIC, 5 bytes

Disp 1:prgmA

This solution requires that the program's name is prgmA.

Displays 1 on a new line forever, or at least until the calculator runs out of free RAM.


Here's an alternative 7 byte solution that is guaranteed to never terminate:

While 1:Disp 1:End

It has the same output as the above solution.


Notes:

  • Each successive prgmA call uses up 16 bytes of free RAM.

  • If there aren't 16 free bytes, then the program crashes with an ERR:MEMORY error.

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

Bash, 3 bytes

top

Haven't seen anyone do this yet. It's tied with the yes answer.

\$\endgroup\$
1
  • \$\begingroup\$ When I tried this, all the more output I got was bash: top: command not found. \$\endgroup\$
    – Bbrk24
    Aug 16 at 0:03
2
\$\begingroup\$

The Hexadecimal Stacking Pseudo-Assembly Language (24):

000000
400000
120000
010000

Continuously prints 0s.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Now that's a long language name \$\endgroup\$ Jun 1 '19 at 17:47
2
\$\begingroup\$

bitch, 3 characters

Yet another answer(am I supposed to be doing that?)

>/<

This program outputs infinite 0's to the console.

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

Bitwise Cyclic Tag But Way Worse, 9 1 byte

2

Turns out that this is a valid answer, I over-complicated that way too much. Outputs endless null characters

Try it Online!

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

Rust, 23 bytes

fn main(){loop{dbg!()}}

Try it online!

Outputs infinitely:

[src\main.rs:1]
[src\main.rs:1]
[src\main.rs:1]
[src\main.rs:1]
[src\main.rs:1]
[src\main.rs:1]
\$\endgroup\$
2
\$\begingroup\$

Shakespeare Programming Language, 86 bytes

8.Ajax,.Puck,.Act I:.Scene I:.[Exeunt][Enter Ajax and Puck]Ajax:Speak thy.Let usAct I.

Try it online!

Prints infinite literal NULs. Since all characters initialize to 0, we can just print the value of one of them and loop back to Act I. I use Jo King's trick of beginning Scene I with Exeunt to save bytes over using a second scene. Pretty simple stuff.

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

VisiCalc, 3 bytes

You need an extra newline to enter the instruction.

/-/

The trailing newline is significant.

Explanation

/   Start a command:
 -  Replicate forever
  / The target for replication is the / character
Extra newline to enter the instruction

You end up with a cell with an infinite number of /'s.
However, the current cell can only show a finite amount
of /'s because cells are trunctuated based on their lengths.
```
\$\endgroup\$
2
\$\begingroup\$

Keg, 4 characters

{A,}

This outputs "A" to the console infinitely.

Non-completing forms

This simply auto-completes the } at the end.

{A,
{🄂

This uses a later-added feature of auto-pushing & printing.

\$\endgroup\$
4
  • \$\begingroup\$ 3 bytes by removing the } \$\endgroup\$
    – lyxal
    Dec 24 '19 at 7:16
  • \$\begingroup\$ You are right. But back then I wouldn't have known that Keg is going to have auto-completion. \$\endgroup\$
    – user85052
    Dec 24 '19 at 8:45
  • \$\begingroup\$ Heh, I know. I just was going around reading old Keg answers to see what has changed since then. \$\endgroup\$
    – lyxal
    Dec 24 '19 at 8:46
  • \$\begingroup\$ 2 bytes \$\endgroup\$
    – lyxal
    Jan 18 '20 at 7:17
2
\$\begingroup\$

Rabbit~, 3

]:[

Prints the number 93 (Int representation of ']') infinitely.

Inverted brackets loops while input is equal, doesn't terminate since input is always ']'

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

7, 1 byte

I

Try it online!

Outputs IôŸ (the bytes 49 f4 9f) repeated forever.

Explanation

In binary, I is 01001001, which is broken into 3-bit chunks to get 010 010 01. This (including the implicit trailing bit 1) is converted to octal to get the instructions 223. These instructions are executed and push 223 on the frame to get ||223.

The last section of the frame (223) is copied to the command list, and executed. 2 duplicates the last section, and the second 2 duplicates the duplicate, leaving ||223|223|223 on the frame. 3 outputs the last section of the frame, 223 (which is automatically converted to 7223 because it contains anonymous commands) and then removes the last two sections. This leaves the frame as ||223.

This process (executing 223) is repeated forever, each time adding 7223 to the output.

The very first 7 specifies the output format as "the same way the source was", meaning that each future command in the output adds three bits. This means that output consists of the bits 010 010 011 111 (from 2237) repeated forever. This is 49f in hexadecimal, so repeating it leads to the bytes 49 f4 9f 49 f4 9f ... .

\$\endgroup\$
2
  • \$\begingroup\$ Why is this non-competing? I see no reason why it couldn't compete with other answers, as the "newer languages aren't allowed" rule has been rendered obsolete and no longer applicable. \$\endgroup\$
    – lyxal
    Jun 16 '20 at 23:22
  • 1
    \$\begingroup\$ Thanks! I didn't know that the rule had been changed, and assumed it still applied because I had seen other answers to this question marked as non-competing without checking when they had been posted. \$\endgroup\$ Jun 17 '20 at 0:34
2
\$\begingroup\$

Malbolge, 1505 bytes

b'a;$9"~}HG{iyxwuu?O=pL:]mHj5!3DCezRQ=+^:('&Y$#m!1So.QOO=v('98$65a!}^{@hyf<WV9sr%4#I20FEJVBfw)btOr@#!7~|4{y1xv.us+rp(om%lj"ig}fd"cx``uz]rwvYnslkTonPfOjiKgJeG]\EC_X]@[Z<R;VU7S6QP2N1LK-I,GF(D'BA#?>7~;:9y16w43s10)p-,l*#(i&%e#d!~``{tyxZpuXsrTTongOkdMhg`Hd]ba`_^W@[ZYXW9UNSRQPOHMLKJ-++FE''<A$?>=<;:387xw43s10/(-&m*)('&}${d!~}|^zyxwvutmVqpiRQlkjiKafedc\E`_^@\[ZYX;V9NMRQ42NGLK.IH*F?DCBA$#>7~;{{8xx5uu2rr/oo,ll)ii&f|e"!aw`{z\r[vXnmVTpongPkNihgJ_dcFa`B^]\UZ=RWV8TSLQ4ON0LE.IHA)E>'BA:?!7~5|38y6/v321q).-&m*)i'&%|{d!~}_{zs\wvutsUqTonPlOjiKgJedFbE`_A]@[Z<X;VU7S6QP22GL/JIB+FEDC%;@?>7~;:987w5v32r0)p-,+k)('~g$#"b~w|uz]xwvutsrqTinQlOjLhgfeH]bE`CB]\>ZSXWVUTSRQPON1LE.I,+*((&&$$""~~||zzxxv4u210/(-n+l)(i&g$ddy~}`u^]\ZvutVlUjSQQOOMMKgfeG]F[DBB@@>><X;99NS6QP3NG0KJ-H+F(('<%@#"~~||z876v.u,sqqoommkki'&%e{dyb``^^\\ZvuWslUjoRmlNNibgJeHcFDDY^A\[Z=XQV987553311/KJI+A*?(&BA@"8!6}{9zxx/43s1*q(ommkki'h%$ecc~}v_^][wZutWrUpohQlkNiLgIIHcbaZ_B]@[><<QVUT6L5JO2MLK.IHGF?(C&%:#!=<|:3z1xvvttr0/.n&m$ki'&f${dyb``^zyxZpYnWUUSSQmPkjLLgfedc\aD_BA?[>YXW:UTSRQJO2ML/J-H**?DC&;$?"!}}{{y765u-t+rppnn%*kii~%f#"!xa|_zyxZpYnWUqpoQgPeNLLJJHHFFDDBB@\?ZY;;PU8S6QPO1G0EJ-HGF)>C&%@#>=~;|92y65v3t1qqp-&ml)j'&gee"!x}|{z]xwYutWlqTonmPkjchgfIHFF[`_^@V?T=;;997SRQ3I2G0.JI+G@)>'%%##!!}}{987w/v-2sqq(onI*6FXDDU0S!Q>O{]sKwp$#s!Uj|nPle+vbK'_7$\n!Y|@{?=,XW:('6_^#3NlkKJIBxe?b'a;^#8[<Z|zVy0SetPb=`o'm8Hk(E3CCe@Rb`<*:sKJ%54"2DS/AQlOj)hK`HdGbn`2^Az.T<;WV87rRo#m[MLjJVyASdu&<$q"8J}}{z2xwwe3cOa/on,JH#iigCUe"yba+*)][wI$4Wr2CRRz?kN*ht9&^cF!mCB{izyx;vt8'65Q42[Z0.hI+xeRQ

Try it online!

This was built with Prof. Masahiko Sakai's LAL toolchain from the following source code.

PROGRAM_START_TO ENTRY@Argh

ROUTINE Argh {
REV_JMP:REV JMP

ENTRY:

OUTPUT
DUP

JMP REV_JMP
}

Online LAL assembler

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

Vim, 10 bytes

<esc> is the byte typed when you press the escape key

qqiq<esc>@qq@q

This will output q infinitely into your vim buffer.

Here's how it works:

qq          # create macro q
  iq        # enter insert mode and type q
  <esc>     # escape to normal mode
  @q        # make the macro call itself
q           # end macro
@q          # call macro q
\$\endgroup\$
2
\$\begingroup\$

MAWP, 4 bytes

[!:]

Explanation:

[     start of loop
!     duplicate top of stack (1)
:     print top of stack
]     end of loop

Prints 1 infinitely

\$\endgroup\$
2
  • \$\begingroup\$ This isn't supposed to work, right? [!:] is 4 bytes anyway. \$\endgroup\$
    – Razetime
    Aug 12 '20 at 10:08
  • 1
    \$\begingroup\$ @Razetime oh wow, of course its not gonna work xd If you don't mind, i'll change it to [!:] \$\endgroup\$
    – Dion
    Aug 12 '20 at 10:33
2
\$\begingroup\$

05AB1E, 1 byte

Try it online!

∞  # [1, 2, ..., ∞]
   # implicit output
\$\endgroup\$
2
\$\begingroup\$

Vyxal, 1 byte

Don't try it online

Polyglots with 05AB1E.

Vyxal, 2 bytes

{፣

A bit more of a creative way to do the job.

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

unsure, 20 bytes

um but uh okay wait

Don't try it online, it freezes the browser. Listen to the code. Even it wants you to wait. Think this through. Don't be like me. Don't lose that unsaved tab.

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

Brainf*ck (4 bytes)

+[.]

Infinitely produces 0x01 character.

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

GFortran, 21 19 bytes

Endless newlines. Try it Online!

1 print*;goto 1
end

Alternate solution (also 19B), hopefully less annoying for @Sapphire_Brick!

do;print*;enddo
end
\$\endgroup\$
1
  • 1
    \$\begingroup\$ This is why I hate Fortran. No labels, just numbers. \$\endgroup\$ Dec 25 '20 at 20:29
2
\$\begingroup\$

Zsh, 15 bytes

while;do 0;done

prints command not found: 0 infinitely

Try it online!

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

PowerShell, 8 bytes

for(){1}

Try it online!

Not the most clever, but it gets the job done.

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

Arduino, 61 60 bytes

Managed to shave off one byte by changing what counts as "output".

void setup(){pinMode(13,1);digitalWrite(13,1);}void loop(){}

Explanation:

void setup() {
  pinMode(13, OUTPUT); // OUTPUT is defined as 1
  // Arduino boards have a built-in LED connected to pin 13, hence the choice of pin
  digitalWrite(13, HIGH); // HIGH is defined as 1
}

void loop() {}

This leaves the built-in LED on, which in a sense is output.


Original answer:

void setup(){Serial.begin(300);}void loop(){Serial.print(0);}

Fills the Serial monitor with 0s.

\$\endgroup\$
1 2 3
4
5
11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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