# 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

# Bash, 3 bytes

top


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

000000
400000
120000
010000


Continuously prints 0s.

• Now that's a long language name – Benjamin Urquhart Jun 1 '19 at 17:47

## bitch, 3 characters

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

>/<


This program outputs infinite 0's to the console.

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

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


# 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~}~


# Intercept 1.1, 37 bytes

Almost exact copy of my answer to a different question.

malware bm bitminer
software install 1


Prints newlines to the terminal. You'll probably have to leave this one overnight, as there is a delay of 5-15 minutes between each newline.

Will print infinitely as long as:
Your internet connection does not drop.
Nobody runs an antivirus program on your system.

Input is marked with a >>. The command prompt is the empty >>.

Assuming a system with only TZ_INFECT installed...


>> malware bm bitminer
creating bm (bitminer)
... wait a minute ...

finished creating bm (bitminer)
>> software install 1
Success
bm installed

...wait...
(newlines)

>>


Note that I'm using a custom client that prefixes [BROADCAST] to all broadcast events.

# How???

TZ_INFECT is Intercept's malware generator. We can generate a bitminer by running malware <name> bitminer. This will create a new piece of software with the given name of type bitminer

We then install the bitminer: software install <index>, where index is the 0-based index of the software as given by software list. This is why I made sure the only piece of software on the system was the malware generator. This places our new bitminer at index 1.

There is a bug in the implementation of bitminer that results in an empty broadcast event to be sent to the client whenever bits are generated. Since bits are generated at random intervals, the broadcasts are sent at random intervals. Forever.

Note: the newlines are harder to detect using the official game client, but you can see them by running a command and watching the newlines slowly push the resulting output off the screen.

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

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


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

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

# Rabbit~, 3

]:[


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

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

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

• 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. – Lyxal Jun 16 '20 at 23:22
• 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. – Pizgenal Filegav Jun 17 '20 at 0:34

# 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"cxuz]rwvYnslkTonPfOjiKgJeG]\EC_X]@[Z<R;VU7S6QP2N1LK-I,GF(D'BA#?>7~;:9y16w43s10)p-,l*#(i&%e#d!~{tyxZpuXsrTTongOkdMhgHd]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_dcFaB^]\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]bECB]\>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)hKHdGbn2^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

# 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


# MAWP, 4 bytes

[!:]


Explanation:

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


Prints 1 infinitely

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

# 05AB1E, 1 byte

∞


Try it online!

∞  # [1, 2, ..., ∞]
# implicit output


# [BASIC] 10 9 bytes

1?:goto 1


Try it online!

Infinite carriage return/line feeds. (I saved a byte when I realized I could just output new lines without a 0 or other character!)

It's the first program every BASIC programmer learnt back in the day! Good old "GOTO" and the hatred it earned from "real" programmers...

Of course, a more "structured" version would use an infinite WHILE loop, but that's 6 bytes more:

while(1):?:wend


Try it online!

(note:TIO truncates the output eventually, but in a standard BASIC interpreter, the code will run forever.)

# C#, 60

class A{static void Main(){for(;;System.Console.Write(1));}}


## Golf-Basic 84, 2 characters

p


Causes upper-right line of 5 pixels to alternate continuously.

PDP-11 Machine Code: 2 bytes (or 6 if you actually want output)

mov -(pc),-(sp)    ; octal opcode = 014746


On many PDP-11's, this instruction will actually do what it says - back the PC up, push its own opcode onto the stack, and repeat until all 64K ram is used up and then just keep filling circularly (or until something like a segfault happens). Not really infinite output, but it's in the spirit.

In 6 bytes you could do this, sending characters directly to the console

mov #SerialPortTxRegAddr,r0  ; oct= 012700 177562 hex = 0x15C0  0xFF72
movb -(pc),(r0)              ; oct= 114710        hex = 0x99C8


Which would send a series of 0xC8 characters (these would be probably be seen as 'H' by any terminal which would be attached to the PDP-11)

Yes, I'm actually that old :-)

## Assembly X86 - 44

Ok Im not a geek with assembly x86 but I wanted just to add this as a possible solution. COnsidering the number of dependencies needed by assembly code this code should be the shortest, a simple infinite loop that prints "x":

loop:
movl $120, %rdi call putchar jmp loop  # 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}  # ~-~! - 17 bytes, with cheating 14 bytes '=|@*:'&*|:'&|.|:  ~-~! has a very limited set of characters, and does not support explicit numbers, so yeah. Outputs infinite .s. If I sway the rules a bit and have the user input the character to be output infinitely, I can have 15 bytes: '=|@*:'&*|:'&^:  Depending on the implementation, the last : for both of these can be left out, lowering the byte counts to 16 and 14. • Please link to a web page describing this language. Google turns up nothing, because the language name is just punctuation. – tbodt Mar 10 '14 at 23:24 • @tbodt It's over here; the language is unimplemented but it wasn't designed for this question and I didn't influence it's development at all. :P – cjfaure Mar 11 '14 at 8:19 ## J 11 echo@-^:_]1  Outputs 0's because inversion (-) does not converge when repeated ad infinitum (^:_). A couple of attempts for AVR, starting with one of the older MEGA/TINY models: inc r1 out DIRC, r0 out DIRC, r1 rjmp .-2  And for XMEGA: inc r0 sts PORTC_DIR, r0 rjmp .-2  Both of these rely on registers being cleared at reset. The output is toggling the direction of PORTC pin 0 (input/output). You need to connect a pull-up resistor to this pin to create a square wave. # Coffeescript 15  alert 0 while 1  • Or: loop alert() – eosterberg Apr 11 '15 at 15:57 # Bash - 13 cat /dev/zero  OK, not the shortest, but I'm surprised this isn't here already. • Even shorter: cat /dev/zero. – tbodt Jun 22 '14 at 22:05 • Ah, thanks! I knew I was forgetting something :) – Jwosty Jun 22 '14 at 22:07 # Bash - 7 Characters echo$0


Prints endless newlines, at least until your computer crashes.

## k4/q (11)

{x}{x""}/-1


The second function, {x""}, sends the empty string to x. If x is an integer, it's interpreted as a file descriptor. If x is 1 or 2, this means to print to stdout or stderr. If x is -1 or -2, this means to additionally print a newline. The result of sending a string to a file descriptor is that file descriptor.

The first function {x} is an idempotent function. (k has an actual idempotent function, ::, but in this context, it would have to be written (::), so this is shorter.)

The construct g f/x, where g and f are functions, is a variation on functional "fold": f x is called, then g f x is tested as a boolean; if it is false, execution stops; if not, f is called on the result of the prior call. (The return value is the result of the last call to f.) Every integer but 0 is truthy, so the -1 returned by {x""} -1 allows the execution to continue.

As a bonus, and at no extra character cost, if you swap the / for a \, you'll waste infinite amounts of RAM too: g f\x does the same thing, but it saves all the intermediate results as it runs--its return value is the full list of intermediate returns of f.

Just for fun, here's another alternate version. It's the same length, but only valid in k (not q):

{x}{x@\$x}/1


This one prints "1"s forever, through more or less the same method, but a couple details are slightly different.

# CJam, 6 bytes

1{1p}h


or

{1p1}g


which prints an infinite number of 1\n` without risk of stack overflow (as there's no recursion).

I think CJam might be younger than the question, but this answer isn't a winner, so I don't see any harm.