# 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? <_< 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. Nov 12 '13 at 20:27
• @Izkata So any answer that crashes your computer is also allowed :D 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. Apr 10 '15 at 21:15

# YABALL, 3 bytes

!.?


Try it online!

Explanation

!                  Go off of "reverse mode" (a mode where the IP goes left instead of right) if in reverse mode, otherwise no-op
.                  Print current cell, which is NUL
?                  Go in "reverse mode"


Basically an infinite loop printing NULs.

The commands are executed like so: !.?.!.?.!.? ...

## MINOL, 5 bytes

GOTO0


Any expression in MINOL that isn't entered as part of a program (that is, isn't assigned a line number by the user) is considered line 0. While seemingly not a part of the official spec (which, as far as I can tell, is a series of letters sent to and subsequently reformatted and published by 'Dr. Dobb's Journal of Computer Calisthenics and Orthodontia' in 1976), lines executed this way always seem to spit out a newline. This obviously wouldn't be the case in a full program, which would take 11 bytes (inc. the trailing CR):

1 PR:GOTO1


# Turing Machine But Way Worse, 27 13 bytes

0 0 0 1 0 1 0


Try it online!

Outputs infinite NUL characters.

# Triangular, 4 bytes

,%0/


Prints 0 repeatedly.

Try it online!

Ungolfed:

  ,
% 0
/


(:S:^):^


Endlessly outputs :S:^

Try it Online!

# Pyth, 3 2 bytes

#d


Try it online!

Prints the string " " (single space) until a print instruction produces an error (which, I mean, I guess could happen).

# PHP, 16 bytes 8 bytes

My first attempt and this Code Golf :)

while(a)


I'm sure I could make it better without that echo? hmm...

• Welcome to PPCG! Hope you stick around! Oct 12 '17 at 14:58
• Thanks! How was my attempt? Not as good as the others how do thy do it? :L Oct 12 '17 at 16:27
• It was pretty good! Best I could have gotten, at least. Most of the other answers are in golfing languages, which are much shorter, but don't let that discourage you! Oct 13 '17 at 15:30
• First, you can leave out the curcly braces, since there is only one statement in the loop anyway: while(1)echo 0;. To golf it further, you can use print instead of echo. Print allways returns 1, so you can then use it inside your while, golfing it to while(print 0);. You can get it even smaller if you're going for infinite error output: while(a);. Feb 13 '18 at 9:04

# 33, 5 bytes

1a[o]


## Explanation:

1a    (Set the accumulator to 1, to allow the loop to continue to run)
[o] (Print the accumulator, 1, forever)


# bitch, 3 bytes

>/<

Try it online!

Explanation

>      Begin loop
/     Print accumulator value (intialised to 0)
<    Loop back to beginning of loop

# TSQL, 16 17 bytes

l:PRINT'1'GOTO l


WHILE 1=1PRINT'1'

# MarioLANG, 7 bytes

>:<
===


Mario will walk back and forth, printing as he does.

Try it online!

# Intcode, 8 bytes

4,0,5,0,1


Outputs "4" an infinite number of times.

## Spice, 26 bytes

Spice module that recursively calls itself. Quite quickly hits a stack overflow.

Given the code is saved to a module named 'x':

;return@OUT a;LOD .\x a a;


## Un-golfed explanation

;a;return@    - define variables: "a" and the required "return"
OUT a;   - output a, implicitly "[0]"
LOD .\x a a;  - call this module, passing a, storing result in a


## Roj, 19 bytes

while(1)do out""end


This produces output because of the [out]: buffer.

# T-SQL, 15 bytes

a:PRINT 0GOTO a


6 years and 10 pages of answers, and no SQL versions yet.

Notes:

• PRINT is 1 byte less than a SELECT.
• A label with a goto is 1 byte shorter than the shortest WHILE statement: WHILE 1=1PRINT 1 (you can't just do WHILE 1 in SQL)
• Depending on the version of SQL Management Studio, the "messages" pane (which displays the result of PRINT statements), might not immediately refresh; this is a client-side UI issue only.
• Seriously? 0goto? yuck. Jun 17 '20 at 0:08
• @Sapphire_Brick You take the bytes where you can get them :) Jun 17 '20 at 13:29

# Go, 59 characters

package main
import "fmt"
func main(){for{fmt.Print(0)}}


# International Phonetic Esoteric Language, 6 bytes

10ɑeoɒ


Will print 0 with newlines forever.

Explanation:

10ɑeoɒ
10     (push the bounds for the loop: from 0 to 1)
ɑ    (pop the bounds and start the loop)
e   (push the current index)
o  (print)
ɒ (check if index < start. 0 < 1, so loop)


# Ruby, 11 9 characters

loop{p:p}


p 0 while 1


## ARM Thumb, Linux syscalls only, 12 bytes

Raw machine code:

2704 2001 4669 2201 df00 e7f9


Assembly:

        .text
.globl _start
.thumb
.thumb_func
_start:
movs    r7, #4    @ write syscall
movs    r0, #1    @ STDOUT_FILENO
mov     r1, sp    @ sp is a valid pointer. May not be legible, but...
movs    r2, #1    @ one byte is fine
svc     #0        @ syscall: write(STDOUT_FILENO, sp, 1)
b       _start    @ loop forever


## ARM Thumb, with libc, 6 bytes

Raw machine code (f7ff fffe is an unlinked libc call):

f7ff fffe e7fc


Assembly:

        .text
.globl main
.thumb
.thumb_func
@ Note that putchar returns the char it put, so we do this:
@ for (;;) putchar(argc);
main:
bl      putchar @ putchar(argc)
b       main    @ Loop forever


Fun fact: These programs do the exact same thing, printing argc % 256 in binary infinitely, since sp[0] at _start is also argc.

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

### Brainf*ck (4 bytes)

+[.]


Infinitely produces 0x01 character.

# Zsh, 15 bytes

while;do 0;done


prints command not found: 0 infinitely

Try it online!

# PowerShell, 8 bytes

for(){1}


Try it online!

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

# Duocentehexaquinquagesimal, 2 bytes

L½


Try it online!

• Did you make this language? Apr 14 at 20:14
• @Redwolf Yes I did. Read the linked Esolang page for more detail about how the language works. :) Apr 14 at 20:15

# Pushy, 3 bytes

3[_


Explanation:

3 \ pushes 3 to the stack

[ \ starts an infinite loop

_ \ prints out the contents of the stack

• [" Infinitely prints newlines (and you need to mark this answer as non-competing) Jan 22 '17 at 15:55

# Dis, 1 byte.

{


Outputs infinite amount of NULL characters; may be slow, depending on the implementation.

# A0A0, 43 bytes

A0A0
A0C3G1G1A0
A0V0O0S1A0
A0A1G-3G-3A0
G-3


Prints 0, 1, 2, up to infinity forever. This wasn't required for the challenge, but the standard loop needs at least three instructions to work and doing this fits in three instructions (the three instructions are also as small as possible). This is a bit more interesting than printing the same number every time. (There are other patterns that would have worked in the same amount of bytes: 1, 2, 4, 8, ...; 0, -1, -2, -3, ...; 1, 3, 5, 7, ...; etc.)

V0O0S1
V0     ; operand, defaults to zero
O0   ; outputs operand
S1 ; increments operand


All other instructions are just there to form an infinite loop.

# Mascarpone, 6.875 bytes

['@.:!]v*:!


Try It Online!

### Explanation:

[     ]     // push a string that will define an operation
'@.        // push the symbol '@ and output it (popping it in the process)
:!      // duplicate the top of the stack and execute it
v*   // push a function/operation that does the above
:! // duplicate the operation, and execute it.


The operation duplicates and executes itself tail-recursively, generating the infinite output.

5 bits are sufficient for the characters used by this program, thus the total size is 55 bits, or 6.875 bytes

# Nim, 16 bytes

while 1>0:echo 0


# q/KDB, 13 chars

while[1;0N!1]


Outputs

1


forever.

{0N!1}/[0<;1]

• {1}{0N!1}/1 for 11 Jan 30 '14 at 20:54