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

• 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

while 1>0:echo 0

# ℒight, 0 bytes

Prints "#" infinitely.

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

## 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. 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 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() 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. Jun 22 '14 at 22:05 • Ah, thanks! I knew I was forgetting something :) 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. # QBasic, 6 (5?) characters ?1:RUN ? is short for PRINT, and RUN without arguments runs the current file from the top. This is the shortest (and most interesting) way to get an infinite loop in QBasic. If, as in the accepted answer, infinite newlines count, then I present this 5-character version: ?:RUN # LOOP, 1 . Outputs 000000000... # This Programming Language, 2 In the spirit of the Befunge answer, i' Outputs 105 indefinitely. # Turing Machine Code (9) (This is the dialect of turing machine code used by many online turing machine simulators) 0 * 1 r * It will endlessly ouput ones while moving rightward along the tape. # Mathematica, 34 33 bytes$IterationLimit=∞;#0@Print@1&[]

If there were no limitation on the maximum length of evaluation chain in Mathematica, #0@Print@1&[] is only 13 bytes, 4 bytes shorter than For[,0<1,Print@1].

Qt 5.4 QMake pro file, 42 chars

defineReplace(A){log(A)return($$A())}$$A()

Is an infinite loop, but sadly gets caught out by qmake interpreter before it can get very far.

AAAA[...]Ran into infinite recursion (depth > 100).

Not sure if that counts under disqualification.

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

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

# PlatyPar, 3 Bytes

1WA

Explanation:

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

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

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

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

• I suggest deleting this answer temporarily until you have released the language Mar 1 '16 at 18:03

# Reng v.1.2, 1 byte

Try it here!

n

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

• If Reng is newer than this challenge, you should state that in your answer. Mar 21 '16 at 3:39

# Fuzzy Octo Guacamole, 3 bytes (Non-Competing)

(non-competing, FOG is newer than the challenge)

(1)

Infinitely outputs 1.

Due to weird implicit output and recursive loops (it executes the code inside the loop using recursion), 1 is outputted by the implicit output.

• Since FOG is newer than this challenge, you should state that in your answer. Mar 21 '16 at 3:39
• @Dennis thanks for catching that. Mar 21 '16 at 16:06

# Scratch, 3 bytes

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

• 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. Oct 6 '16 at 18:57
• That's because CubeUpload is down at the moment. Oct 8 '16 at 18:05
• Well, can you posts the ScratchBlocks version of the script at least (golfed)? Oct 8 '16 at 18:11

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

# Quetzalcoatl (non-competing), 14 chars

while 1: ::' '

This is for an older version of Quetzalcoatl.

• The latest revision of your answers makes it identical to this answer. May 6 '16 at 15:41