136
\$\begingroup\$

Your task is to create the shortest infinite loop!

The point of this challenge is to create an infinite loop producing no output, unlike its possible duplicate. The reason to this is because the code might be shorter if no output is given.

Rules

  • Each submission must be a full program.
  • You must create the shortest infinite loop.
  • Even if your program runs out of memory eventually, it is still accepted as long as it is running the whole time from the start to when it runs out of memory. Also when it runs out of memory, it should still not print anything to STDERR.
  • The program must take no input (however, reading from a file is allowed), and should not print anything to STDOUT. Output to a file is also forbidden.
  • The program must not write anything to STDERR.
  • Feel free to use a language (or language version) even if it's newer than this challenge. -Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. :D
  • Submissions are scored in bytes, in an appropriate (pre-existing) encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score - if in doubt, please ask on Meta.
  • This is not about finding the language with the shortest infinite loop program. This is about finding the shortest infinite loop program in every language. Therefore, I will not accept an answer.
  • If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainf**k-derivatives like Alphuck), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.
  • There should be a website such as Wikipedia, Esolangs, or GitHub for the language. For example, if the language is CJam, then one could link to the site in the header like #[CJam](http://sourceforge.net/p/cjam/wiki/Home/), X bytes.
  • Standard loopholes are not allowed.

(I have taken some of these rules from Martin Büttner's "Hello World" challenge)


Please feel free to post in the comments to tell me how this challenge could be improved.

Catalogue

This is a Stack Snippet which generates both an alphabetical catalogue of the used languages, and an overall leaderboard. To make sure your answer shows up, please start it with this Markdown header:

# Language name, X bytes

Obviously replacing Language name and X bytes with the proper items. If you want to link to the languages' website, use this template, as posted above:

#[Language name](http://link.to/the/language), X bytes

Now, finally, here's the snippet: (Try pressing "Full page" for a better view.)

var QUESTION_ID=59347;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=41805;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"//api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(index,answers){return"//api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=false;comment_page=1;getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}getAnswers();var SCORE_REG=/<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;var OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(a){return a.owner.display_name}function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))body='<h1>'+c.body.replace(OVERRIDE_REG,'')+'</h1>'});var match=body.match(SCORE_REG);if(match)valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,});else console.log(body)});valid.sort(function(a,b){var aB=a.size,bB=b.size;return aB-bB});var languages={};var place=1;var lastSize=null;var lastPlace=1;valid.forEach(function(a){if(a.size!=lastSize)lastPlace=place;lastSize=a.size;++place;var answer=jQuery("#answer-template").html();answer=answer.replace("{{PLACE}}",lastPlace+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link);answer=jQuery(answer);jQuery("#answers").append(answer);var lang=a.language;lang=jQuery('<a>'+lang+'</a>').text();languages[lang]=languages[lang]||{lang:a.language,lang_raw:lang,user:a.user,size:a.size,link:a.link}});var langs=[];for(var lang in languages)if(languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function(a,b){if(a.lang_raw.toLowerCase()>b.lang_raw.toLowerCase())return 1;if(a.lang_raw.toLowerCase()<b.lang_raw.toLowerCase())return-1;return 0});for(var i=0;i<langs.length;++i){var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}
body{text-align:left!important}#answer-list{padding:10px;width:500px;float:left}#language-list{padding:10px;padding-right:40px;width:500px;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="language-list"> <h2>Shortest Solution 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> <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> <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\$
13
  • 50
    \$\begingroup\$ I've got to start posting programs with a negative byte count to beat all these empty files! \$\endgroup\$
    – CJ Dennis
    Oct 3 '15 at 4:32
  • 4
    \$\begingroup\$ This challenge is interesting because it brings out lots of 0 byte languages (some of which are NOT esolangs). FWIW, most declarative languages have an implicit infinite loop because declarative languages don't have loops in their syntax (they assume they're running in an infinite loop). Ladder diagrams are perhaps among the oldest such languages. Then you have the Instruction Language (IL), a sort of assembly for PLCs that also assume an infinite loop. ILs, like assembly are different between manufacturers \$\endgroup\$
    – slebetman
    Oct 5 '15 at 9:36
  • \$\begingroup\$ Are programs that read and execute their own source code allowed, or does file I/O break the "must take no input" rule? \$\endgroup\$ Oct 6 '15 at 13:05
  • 1
    \$\begingroup\$ @ThisSuitIsBlackNot Yes, file input is allowed. \$\endgroup\$
    – user41805
    Oct 6 '15 at 16:47
  • \$\begingroup\$ Can you print "", an empty string? \$\endgroup\$ Mar 7 '16 at 23:39

547 Answers 547

1
12 13
14
15 16
19
1
\$\begingroup\$

ezfuck, 2 bytes

+{

Basically equivalent to +[] in BrainFuck.

+ increments the current cell to 1, then { jumps back a single command while the current cell is non-zero.

\$\endgroup\$
4
  • \$\begingroup\$ The "non-competing" rule has been lifted, which means that this is a competing submission. \$\endgroup\$ Jul 9 '17 at 23:49
  • \$\begingroup\$ @Challenger5 Oh, thanks. Are you sure? It doesn't say in the question that new languages are allowed. \$\endgroup\$ Jul 9 '17 at 23:53
  • \$\begingroup\$ Marking as NC was the default for newer languages, but it was changed after a recent meta discussion \$\endgroup\$ Jul 10 '17 at 0:00
  • \$\begingroup\$ @Challenger5 Awesome, thank you for pointing me to that page! That's certainly a welcome change \$\endgroup\$ Jul 10 '17 at 0:03
1
\$\begingroup\$

05AB1E, 1 Byte

[

Try it online!

[  # begin infinite loop
\$\endgroup\$
1
\$\begingroup\$

International Phonetic Esoteric Language, 3 7 4 bytes

01ɑɒ
10   (loop bounds 0-1, set current IDX=0, LIM=1)
  ɑɒ (since IDX<LIM, infinite loop)

7 bytes. Labels are fun.

|a|ʟ|a|

Defines a label a and jumps to a.


3 bytes (WIP language) (OLD)

ɘ0e

What the code does is push 0, then check if the stack is falsy, which 0 is. Then it jumps, without any output.

No TIO interpreter yet, but is runnable by cloning the repository above, and calling python3 main.py "code here".

ɘ0e
ɘ   ; begin falsy jump
 0  ; push 0
  e ; pop, if falsy jump; else end falsy jump
\$\endgroup\$
1
\$\begingroup\$

sed, 3 bytes

:;b

Pretty simple. Make an unnamed label, then branch to it. Not all versions of sed support unnamed labels, in which case there is a 5 byte solution.

:a;ba
\$\endgroup\$
1
\$\begingroup\$

NDBall, 11 bytes

(0)>0
(1)<0

the ball bounces back and forth forever

the ball starts on (0) then is told to move forward along the 0th dimension making it go to (1)

then at (1) it is told to move backward along the 0th dimension, making it go back to (0)

the new line is mandatory, hence the extra byte

this was done in NDBallSim V1.0.1

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

Pixilang, 8 bytes

a:goto a

A pixel based programming language.

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

C#9, 8 bytes

for(;;);

In C#9, they introduced Top-Level Statements which means one source file no longer needs any boilerplate.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Welcome to the site, nice first answer! This is the shortest C# code I've seen in a while :p \$\endgroup\$ Nov 23 '20 at 20:13
1
\$\begingroup\$

ARM Thumb-2 machine code, 2 bytes

e7fe
1:
        b.n     1b

It is an instruction that jumps to itself. There isn't much else to it.

Being a single narrow instruction, it is the shortest possible solution.

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

Canvas, 2 1 byte

Try it here!


redirects execution to the main program. This means the program contains a call to itself, so it runs forever.

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

vJASS (Warcraft 3), 58 bytes

//! inject main
loop
endloop
//! dovjassinit
//! endinject

Without exitwhen inside the loop, it loops infinitely.

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

Pxem, Filename: 4 bytes + Content: 0 bytes = 4 bytes.

  • Filename: .w.a
  • Content: none
\$\endgroup\$
1
\$\begingroup\$

BRASCA, 3 2 bytes

1J

Try it!

Explanation

1J - Move the pointer back one character.
\$\endgroup\$
1
\$\begingroup\$

convey, 2 bytes

5]

Try it online!

In convey, } is an output, and ] is a dummy output or sink. In convey, all static numbers and strings continuously output, so 5] will continuously output 5 to a dummy output, looping forever.

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

Duocentehexaquinquagesimal, 2 bytes

Try it online!

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

ABC, 2 bytes

al

l is the actual infinite loop, a is just a placeholder to increment the accumulator at each iteration.

Try it online!

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

CSASM v2.4.0.2, 26 bytes

func main:
.lbl a
br a
ret
end

Endlessly jumps execution back to the label a, which just refers to the br instruction itself.
The ret instruction and end token are needed for the function to compile.

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

Jellyfish, 5 bytes

\>1
1

Try it online!

jellyfish doesn't have implicit output, so nothing is printed here.

Explanation

given with positions.

(0,0) \ iterate the following function: 
(1,0)  >  increment 
(0,1) 1 on one
(2,0) till 1 is reached.
\$\endgroup\$
1
\$\begingroup\$

Splinter, 5 bytes

A{A}A

Try it online!

Interpreter crasher. Defines A as itself, then calls A, with infinite recursion.

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

MMIXAL, 10 bytes

Main JMP @

Assembly language. Has jump-to-self. Done. (This compiles down to four bytes of actual code, F0000000.)

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

Elixir, 38 18 bytes

l=&[&1.(&1)];l.(l)

Try it online!

l=&[&1.(&1)];l.(l)  # full program
 =          ;       # set...
l                   # variable...
 =          ;       # to...
  &[       ]        # function taking one argument that...
      .(  )         # calls...
    &1              # first argument...
      .(  )         # with argument...
        &1          # first argument
              .( )  # call...
             l      # variable...
              .( )  # with argument...
                l   # variable
\$\endgroup\$
0
1
\$\begingroup\$

Dis, 0 bytes.

Yes, a blank program:

How it works

  • The Dis language accepts an empty program.
  • Begins with c=0.
  • mem[i]=0 for each i, so every cells stand for NOP.
  • Unlike Malbolge, the Dis language does never modify the program by default.
  • This goes forever.

Since TIO doesn't have Dis by native, I made the interpreter. Try it online!

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

yuno, 2 bytes

1¿

This will freeze your browser window so I took the TIO link out.

 ¿    While
1     1
      (1)

The 1-byter ɫ (call this link) dies to recursion which unfortunately outputs to STDERR. I might add a flag to disable that in the future.

This will keep applying 1 to 1 until 1 is not true and then print the result after infinite time. Hopefully that's acceptable. If not, you can add the d flag to disable implicit output, or do 1¿ɳ“” - evaluate 1¿, then take ignore that and take the right argument to ɳ, which is “”, an empty string.

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

Mascarpone, 8 bytes

[:!]v*:!
[  ]v*   // define and push a new operation
 :!   :! // duplicate and execute the operation on the stack
\$\endgroup\$
1
\$\begingroup\$

Python3, 20 bytes

(-14 bytes thanks to Redwolf Programs)

s = "exec(s)"
exec(s)
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to Code Golf! I can't check right now, but are you sure this doesn't hit any sort of recursion limit? Also, the print('') isn't necessary, and might be printing newlines. \$\endgroup\$ Jun 28 '21 at 19:28
  • \$\begingroup\$ You can remove three spaces, and print('') like Redwolf mentioned prints newlines which is not allowed, and this hits the recursion limit during compilation (and thus outputs to STDERR when crashing, which is disallowed) \$\endgroup\$
    – hyper-neutrino
    Jun 28 '21 at 20:55
1
\$\begingroup\$

Maze, 7 Bytes

^^
%R%L

Maze is a 2D language where cars navigate through a maze and execute instructions in cells they visit. This code starts a car ^^, which by default moves downwards. The next instruction redirects the car to the right %R. That lands on a cell that redirects the car to the left %L, creating an infinite loop.

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

Binary Pi Calculus, 6 bytes

0x73 0xB8 0x1B 0xDB 0xB0 0x00

Unfortunately, I could find no existing BPC interpreter. If one does exist, please let me know.

Explanation

0x73     0xB8     0x1B     0xDB     0xB0     0x00
01110011 10111000 00011011 11011011 10110000 00000000
01110011101110000001101111011011101100000 0000000
011                                       Run the following two processes in parallel
   100    1110                            Write the free variable 0...
      1110                                ...to the free channel 0
              000                         End first process
                 001                      Run the following on an infinite number of threads:
                    1011110               Read from the free channel 0 to the bound variable 0
                           110    1100    Write the bound variable 0...
                              1110        ...to the free channel 0
                                      000 End second process

The corresponding pi-calculus program is

a<a>|!a(a).a<a>

Reads and writes are blocking, so each thread will be executed sequentially. As there are an infinite number of them, the program will therefore never halt.

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

ErrLess, 0 bytes

An empty program in ErrLess is an infinite loop! This is because if the IP reaches the end of the program it loops back to the start, so programs have to be explicitly halted using ..

ErrLess is a stack-based language I made for fun over the last few months. You can read the docs here, and I also started a tutorial.

Try it online!

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

Pure CPython 3.10 Bytecode, 2 bytes

Hex:

71 00

Disassembly:

    >>    0 JUMP_ABSOLUTE            0 (to 0)

Attempt This Online!

\$\endgroup\$
2
  • \$\begingroup\$ I know all instructions are supposed to be 2 bytes long, but this still works if you remove the zero byte. Does the runner code somehow pads this or does JUMP_ABSOLUTE work without an argument? \$\endgroup\$
    – ovs
    Oct 30 '21 at 10:04
  • 1
    \$\begingroup\$ @ovs that would mean the bytecode interpreter is reading one byte past the end of the bytes object's buffer, and the byte after the end happens to be a 0 byte. This probably works most of the time, but it's too far into undefined behaviour IMO \$\endgroup\$
    – pxeger
    Oct 30 '21 at 10:16
0
\$\begingroup\$

HPPPL, 16 bytes

while 0=0 do end
\$\endgroup\$
0
\$\begingroup\$

C++ Template Meta-Programming, 48 bytes

template<int n>class S{enum{v=S<n-1>::v}}S<1>::v

There is an infinite loop in the template, so this doesn't compile. Other stuff that doesn't compile, but doesn't need to for the template to recurse (S being private, S<1>::v being free floating)

Can be run at http://coliru.stacked-crooked.com/ for error g++: internal compiler error: Segmentation fault

g++ -std=c++14 -O2 -Wall -pedantic -pthread -ftemplate-depth=162345 main.cpp && ./a.out
\$\endgroup\$
3
  • \$\begingroup\$ Not sure if that is compliant with the rules as it doesn't run out of memory when it stops. If you want to do that, there is the -ftemplate-depth compiler option in gcc that allows you to set the recursion depth to something very high so you'll at least get a segfault out of it. \$\endgroup\$
    – iFreilicht
    Oct 16 '15 at 14:23
  • \$\begingroup\$ @iFreilicht Yeah, I suppose you're right. I couldn't (be bothered to...) find a online complier that supported that. \$\endgroup\$ Oct 16 '15 at 14:33
  • 1
    \$\begingroup\$ coliru.stacked-crooked.com \$\endgroup\$
    – iFreilicht
    Oct 16 '15 at 14:35
1
12 13
14
15 16
19

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.