145
\$\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\$
14
  • 52
    \$\begingroup\$ I've got to start posting programs with a negative byte count to beat all these empty files! \$\endgroup\$
    – CJ Dennis
    Oct 3, 2015 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, 2015 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, 2015 at 13:05
  • 1
    \$\begingroup\$ @ThisSuitIsBlackNot Yes, file input is allowed. \$\endgroup\$
    – user41805
    Oct 6, 2015 at 16:47
  • \$\begingroup\$ Can you print "", an empty string? \$\endgroup\$
    – AAM111
    Mar 7, 2016 at 23:39

566 Answers 566

1
15 16 17 18
19
0
\$\begingroup\$

And, 0 bytes


No && exit, therefore loops forever.

\$\endgroup\$
0
\$\begingroup\$

A0A0, 2 bytes

G0

Goes 0 lines below the current line.

\$\endgroup\$
1
  • \$\begingroup\$ A0A0 consumes the instructions it has executed. So once it has jumped to the same line, the instruction will be gone and the program will halt. \$\endgroup\$ Jun 14, 2021 at 10:40
0
\$\begingroup\$

Fastlane, 0 bytes


The pointer speed defaults to 1 and wraps around; there isn't a $ instruction to halt the pointer in this program.

\$\endgroup\$
0
\$\begingroup\$

@, 2 bytes

¤

Loops forever, takes arbitary input and has no output.

\$\endgroup\$
0
\$\begingroup\$

Kipple (cipple), 6 5 bytes

1>a(a

Pretty simple, just pushes 1 to stack A, and then begins a loop that only ends if stack A is empty

-1 byte, since the ending bracket isn't necessary in cipple for some reason

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Element, 3 bytes

!{]

Negates top of stack & executes while.

TIO

\$\endgroup\$
0
\$\begingroup\$

Whenever: 4 bytes

1 1;

Is actually an example from the specification. The instruction causes line 1 to put itself back on the to-do list.

\$\endgroup\$
0
\$\begingroup\$

NULL, 2 bytes

41

Code in the NULL language is a number.

The interpreter sets X = 41 and Y = 1. Afterwards, it divides X by its smallest prime factor (41) and multiplies Y by that, so then X = 1 and Y = 41.

Afterwards, it performs an action which corresponds to that prime factor. The action for 41 is to swap X and Y, so X = 41 and Y = 1.

The program ends when X = 1, which will never happen with this code.

\$\endgroup\$
0
\$\begingroup\$

///, 3 bytes

///

Try it online!

Explanation

This replaces nothing with nothing. It runs forever because when it replaces nothing with nothing, it has to replace that nothing with another nothing, and it does this indefinitely.

\$\endgroup\$
2
0
\$\begingroup\$

QWOP, 2 bytes

OO

Explanation

The command O return[s] the pointer to the last O, if one exists. So this will run indefinitely without producing output.

\$\endgroup\$
0
\$\begingroup\$

tq, 3 bytes

"")

Explanation

"",  # Define an empty string
   ) # Extend the list forever
\$\endgroup\$
0
\$\begingroup\$

Kotlin, 14 bytes

{while(1>0){}}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Husk, 2 bytes

LN

Try it online!

Explanation

 N   The natural number list       . [1, 2, 3, 4, ...]
L    Try to find the length of that. ???

     Weirdly, Husk isn't lazy in this case.
     So it will loop forever as the
     counter approaches positive infinity.
\$\endgroup\$
0
\$\begingroup\$

J, 6 bytes

<^:_[1

Try it online!

Explanation

<      # A monad
 ^:_   # Done infinity times
    [1 # To an argument
\$\endgroup\$
0
\$\begingroup\$

Haskell, 9 bytes

main=main

Defines the main function (required to run) recurring on itself, resulting in an infinite loop.

\$\endgroup\$
0
\$\begingroup\$

J, 5 bytes

-^:]_

Try it online!

-        Negate the given number
 ^:]     Repeat (right arg) times
    _    The right arg: infinity
         Repeat (infinity) times means to find the fixed point,
         but there is none since it alternates between _ (inf) and __ (-inf)

0&-~_

Try it online!

0&-~_    `~` gives the argument `_` to both sides of `0&-`
         so it is equivalent to `_ (0&-) _`
_ (0&-) _
  (0&-)      Negate the given number
_            If you give left arg to a `&`-function, it becomes repeat count
             so it acts exactly like `^:_` (find the fixed point)
        _    The initial value

This one works with any other single-digit integer in the place of 0.

\$\endgroup\$
0
\$\begingroup\$

Ruby, 6 bytes

The loop construct produces an infinite loop. Thanks, Yukihiro Matsumoto.

loop{}
\$\endgroup\$
0
\$\begingroup\$

Python 3, 15 bytes

def f():f()
f()

Try it online!

A function calling itself (till maximum recursion depth exceeded)

\$\endgroup\$
0
\$\begingroup\$

Rockstar, 17 9 bytes

while 1
1

Try it here (Code will need to be pasted in)

\$\endgroup\$
0
\$\begingroup\$

Add++, 5 bytes

Dx,+1

Try it online!

Very basic, this simply executes the following pseudocode:

x = 0
Do
  x = x + 1
While x > 0

For 1 extra byte, we can remove any possibility of running out of memory if x becomes too big:

Dx,x:1

Try it online!

which simply sets x equal to 1 each time, rather than x+1

\$\endgroup\$
0
\$\begingroup\$

Arn, 3 bytes

[[{

Try it!

Takes advantage of Arn's pretty printing of matrices combined with an infinite, empty sequence.

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 6 bytes

{redo}

Try it online!

\$\endgroup\$
0
\$\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
0
\$\begingroup\$

Uselesslang, 0 bytes

Explanation:

<empty>
<EOF>   goto first char
\$\endgroup\$
0
\$\begingroup\$

Thunno 2, 1 byte

Try it online! (Note: it will probably crash your browser)

\$\endgroup\$
0
\$\begingroup\$

Arm/Thumb/MIPS/SPARC/PowerPC assembly, 3 bytes

b 0

Which produces on my machine:

AArch64 machine code, 4 bytes

0: 14000000  b 0

Or with --target=armv7m-none-eabi gives @EasyasPi's answer.

Try compiling (not running) it online to several different machine languages here!

\$\endgroup\$
1
15 16 17 18
19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.