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 Commented Nov 9, 2013 at 20:00
• Does "infinite until your computer crashes" count? <_< Commented Nov 10, 2013 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. Commented Nov 12, 2013 at 20:27
• @Izkata So any answer that crashes your computer is also allowed :D Commented Jul 11, 2014 at 20:11
• @Doorknob So really, the challenge is to produce infinite output in a finite amount of time. Sounds easy enough. Commented Apr 10, 2015 at 21:15

for()print(1)

Try it online!

> 1
>> Output 1
>> While 1 2

Try it online!

Aceto, 2 bytes

pO
p  prints the top stack element (implicit 0)
O  returns to the origin of the program

Try it online!

alternate version:

nO
n prints a newline, O returns to origin

Forked, 1 byte

%

Prints the top of stack (0 if empty). The IP wraps upon hitting the edge of the playing field, looping infinitely.

Wumpus, 2 bytes

OO

Try it online!

Outputs infinite 0s

Funnily enough, even though a single O causes an infinite loop, a new command is only executed once it leaves the current cell, meaning the pointer gets trapped inside the O triangle, bouncing off the walls. Adding another cell (which could be almost any cell that doesn't end the program such as @ or %) allows the pointer to escape and execute the Output instruction again.

Momema, 5 bytes

j0!j1

Try it online! Outputs to STDERR. Requires the -d interpreter flag.

The Momema interpreter has a -d (debug) flag that enables a ! instruction, which outputs some debugging information to STDERR.

Explanation

j  0  #  label j0: jump past label j0 (no-op)
!     #            debug
j  1  #  label j1: jump past label j0 (back to start)
• Remember, non-standard flags add to byte count by default Commented May 18, 2018 at 3:11
• @Draconis Per a five-month old meta consensus they dont. Commented May 18, 2018 at 3:35
• Ah, my bad! Apologies! Commented May 18, 2018 at 3:54

axo, 2 bytes

{_

Try it online!

Implicit 0 on top of the stack
{  prints it
_  returns to origin, or 0,0

FALSE, 7 bytes

[^.^]3#

This works in some FALSE interpreters (http://www.quirkster.com/iano/js/false-js.html (Paste the code, click "show", then click "step" a bunch of times (not "run" because it's an infinite loop!))). Outputs an infinite amount of -1s.

Explanation:

Some versions of FALSE are weakly typed, so a normal number can be used as a function pointer.

[^.^] pushes a function to the stack. (specifically, the character in the code that is starts at.) In this case, it pushes the number 0.

3 Pushes the number 3, which when called as a function will start execution at the ] of the previous function (meaning that it skips all the code)

# Is a "while" loop. It pops two functions, then calls the first function (that is, the one which was PUSHED first). It then pops a value from the stack, and if this value is true, it runs the second function and repeats. If the value is false, it continues.

Our function [^.^] will first use ^ to push the next character of STDIN (if input is empty, it pushes -1), then . prints the numerical value (-1), and ^ pushes the next value of input again. This is the value which will be "returned" and used in the loop. Because it is non-zero, the second "function" is called (which is just a number pointing to a location in the code), and the interpreter immediately sees a ], causing it to return from the function.

Stax, 3 bytes

W1P

Run and debug it

Outputs 1 forever. Since Stax terminates when trying to peek or pop an empty stack, I am not sure how to do it in 2 bytes or less.

• Since W1Q also works and differs in only the final bit, the first 23 bits of this work regardless of the 24th; could it be claimed that this is 2.875 bytes? Is this a dumb question? Commented Apr 6, 2018 at 11:21
• Interesting idea, but I honestly don't know. Sadly W1Q will stack overflow after some time ... Commented Apr 7, 2018 at 0:30

ORK, 170 bytes

There is such a thing as a o
A o can i

When a o is to i:
I have a scribe called W
W is to write "!"
I am to loop

When this program starts:
I have a o called O
O is to i

Try it online!

Objects R Kool. Maybe, but they're inconvenient (why can't I just loop the main function?).

Burlesque - 2 bytes

bc

bc box cycle

Rather boring. bc encloses the top of the stack in a block and then infinitely repeats this block and thus when the value is printed when the program stops it'll obviously never stop producing output.

MathGolf, 4 3 bytes

Äo↔

Try it online!

Explanation

Ä     start block of length 1
o    print TOS without popping
↔   do while false without popping

JavaScript + HTML, 56 bytes

(g=_=>requestAnimationFrame(_=>document.writeln(g())))()

Turing Machine But Way Worse, 13 bytes

0 0 1 1 0 1 0

Try it online!

prints chr(128),chr(128+64),chr(128+64+32),...,chr(128+64+...+2+1) infinitely.

No explanation since the code is self-explanatory.

JVM bytecode (OpenJDK asmtools JASM), 194 bytes

enum i {public static Method main:"([Ljava/lang/String;)V" stack 2 locals 1 {l:getstatic java/lang/System.out:"Ljava/io/PrintStream;";ldc 0;invokevirtual java/io/PrintStream.print:(I)V;goto l;}}

Ungolfed

enum i {
public static Method main:"([Ljava/lang/String;)V" stack 2 locals 1 {
l:
getstatic java/lang/System.out:"Ljava/io/PrintStream;";
ldc 0;
invokevirtual java/io/PrintStream.print:(I)V;
goto l;
}
}

First we get a reference to System.out, then we just invoke void print(int) with zero. Repeat until the heat death of the universe, since this method never returns.

Using enum instead of class saves 1 byte, along with using ldc 0 instead of iconst_0 to save 2 more bytes.

Bonus points for not decompiling correctly in the Fernflower decompiler, no?

Python: (16 characters)

while 1:print(0)
• I don't believe you need the parentheses around the 1. while 1:print(0) should work just fine. Commented Feb 14, 2019 at 20:30
• You can also save a byte on the print by using python 2 Commented Feb 14, 2019 at 21:34
• you don't even need the 0 since python prints a newline
– Jo King
Commented Feb 14, 2019 at 22:11
• You are right @Joking. New line is invisible output. Commented Feb 14, 2019 at 22:14
• while 1:print() would print a newline Commented Mar 3, 2019 at 17:45

main={print 1}.

Try it online!

loop {.say}

Try it online!

Brian & Chuck, 8 bytes

!{?
!{.?

Try it online!

Brian simply restarts Chuck and Chuck sets Brian's instruction pointer to the left end, prints it and restarts Brian.

Produces endless "!!!!!!..."

Brain-Flak, 10 bytes

(()){(())}

Try it online!

I don't know if this counts as a valid answer because Brain-Flak prints the contents of the active stack and this code just fills the stack.

(())    push 1 on stack
{       while top of stack != 0
(())  push 1 on stack
}

Lua, 18 bytes

::a::print()goto a

Try it online!

Shortest I was able to came up with (beats any loop). Prints newlines forever.

MarioLANG, 7 bytes

>:<
===

Try it online!

Infinitely prints zeroes; not much else to say about it.

• I've been reading trough the answers here and I'm sure I've seen the 100% identical one. Commented Aug 21, 2020 at 11:52
• I do see an identical one now that you mention it, but I also see its post date being 9 days after mine, unless there's a third somewhere. Commented Aug 23, 2020 at 7:31

Element, 5 bytes

!{A`]

This outputs A to the console forever.

TIO

AlphaBeta, 2 bytes

MN

Try it online!

Outputs infinite null bytes.

Explanation

# All registers are initialized to 0
M  # Output the number in register 3
N # If register 3 is 0, goto the position at the position register.

Brainetry--live-output, 55 bytes

Uses the --live-output flag, otherwise output to the console would be deferred to the end of the program, which never happens because we have an infinite loop going on.

a b c d
a b c d e f g h
a b c d e f g
a b c d e f g h i

This is a golfed version of this program:

Lets produce infinite output.
This is really simple, all it takes is:
A cell with a non zero value
and the --live-output flag also needs to be on.

If you want to try this, clone the linked github repo and run python brainetry.py btry/infinite_output.btry --live-output.

C, 292826 23 bytes

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

-3 @rtpatx

gcc won't like it, but it compiles.

Outputs null bytes continuously. You can swap out the 0 for anything 0-9.

You can use 7 if you really hate your speakers.

• 26 bytes: main(){for(;;)putchar(0);} Commented Dec 25, 2017 at 1:55
• Suggestion coming a long time later, 23 bytes main(){main(puts(""));} Commented Jun 24, 2020 at 19:17
• @rtpatx nice! Editing. Commented Jun 24, 2020 at 19:51

Knight, 4 bytes

W1O1

Try It Online!

Prints 1 forever.

Pyth, 4 bytes

Pyth is a new programming lenguage, so this answer doesn't count.

.V"0

Explanation:
.V   - Forever loop
"0 - Outputs zeros
• This can be golfed to #0
– Blue
Commented Feb 20, 2016 at 12:56

Röda, 12 bytes

{[0]while{}}

This is an anonymous function that prints zeros infinitely.

Pascal, 50 B

Full program compatible to ISO standard 7185 “Pascal”.

program p(output);begin while 8=8 do writeLn end.
program p(output);begin while 0=0 do write(1)end.

Some dialects such as Free Pascal do not require and actually ignore the program header (the program p(output);). There you could omit those 18 bytes, so it’s 32 bytes in total.