121
\$\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\$
  • 41
    \$\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
  • 3
    \$\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\$ – ThisSuitIsBlackNot Oct 6 '15 at 13:05
  • 1
    \$\begingroup\$ @ThisSuitIsBlackNot Yes, file input is allowed. \$\endgroup\$ – Cows quack Oct 6 '15 at 16:47
  • \$\begingroup\$ Can you print "", an empty string? \$\endgroup\$ – OldBunny2800 Mar 7 '16 at 23:39

477 Answers 477

1
\$\begingroup\$

Cardinal, 2 bytes

%$

or

$%

In Cardinal each pointer carries exactly 2 unsigned 8 bit values, one active, one inactive. Both are initialized to 0

% creates 4 pointers moving in the cardinal directions.

$ moves the pointer to x,y = active,inactive value of the pointer

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

Staq, 2 bytes

()

( jump to corresponding ) if the top stack value is greater than 0

) jump back to corresponding ( if the top stack value is 0 (or if it does not exist)

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

PARI/GP, 9 bytes

while(1,)

Or equivalently:

until(0,)
\$\endgroup\$
1
\$\begingroup\$

AppleScript, 10 Bytes

In Script Editor... it's 10 bytes, which is way better than I expected nonetheless.

repeat
end

Thanks to @Mark for pointing out that the 0 byte "loop" was no loop at all.

\$\endgroup\$
  • \$\begingroup\$ osascript -e "" doesn't loop forever. A quick check with Instruments shows that it's simply performing a blocking read on standard input. \$\endgroup\$ – Mark Oct 19 '15 at 20:02
  • \$\begingroup\$ Hmm. I'll update, seems that way. Thanks. \$\endgroup\$ – Addison Crump Oct 19 '15 at 20:24
1
\$\begingroup\$

GOLF, 10 bytes

didn't see a golf response

lx:
jmp lx

lx: sets a goto marker, jmp sends you to the marker. Note that the marker name cannot be a single character (as far as I know) because the alphabet characters are reserved for registers.

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

Gema, 18 15 characters

\A=@a{a};a:\P?=

Sample run:

bash-4.3$ gema '\A=@a{a};a:\P?='
\$\endgroup\$
1
\$\begingroup\$

Perl 6, 7 5 bytes

The standard boring one is just an empty loop (;;){} construct.
( spelled for(;;){} in other languages )

loop {} # 7 bytes

There are also exotic ones as well

  • infinite sequence of the Any type object ( default value in $_ )

    .roll(*) # 8 bytes
    
  • unterminated sequence generator (0,1,2,3,4 ... Inf, Inf, Inf, Inf)

    0...* # 5 bytes
    
\$\endgroup\$
1
\$\begingroup\$

Hassium, 17 Bytes

Calls the main() infinitely.

func main()main()

Run online and see here

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

JacobFck

:A_A

Expanded and commented here

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

ಠ_ಠ, 31 bytes

ಠ4ಠ
ಠ4ಠ
ಠ1ಠ
ಠ?ಠ

Explanation

ಠ4ಠ # Push 4 to the stack [4]
ಠ4ಠ # Push 4 to the stack [4,4]
ಠ1ಠ # Push 1 to the stack [4,4,1]
ಠ?ಠ # Essentially: go to line 4
\$\endgroup\$
  • \$\begingroup\$ This needs a special encoding. \$\endgroup\$ – Addison Crump Nov 18 '15 at 10:33
  • \$\begingroup\$ What does that mean? \$\endgroup\$ – Mama Fun Roll Nov 18 '15 at 14:37
  • \$\begingroup\$ As in, a special encoding should be made for this so that it's not too long in bytes. \$\endgroup\$ – Addison Crump Nov 18 '15 at 14:37
  • \$\begingroup\$ Ah, I see. Any suggestions? \$\endgroup\$ – Mama Fun Roll Nov 18 '15 at 14:42
  • \$\begingroup\$ Are there any characters that ಠ_ಠ would never use? \$\endgroup\$ – Addison Crump Nov 18 '15 at 14:43
1
\$\begingroup\$

Pyth, as of 11/3/15: 1 byte

#

There is no trailing space in this version. The requirement that statements have a value has been removed.

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

Haystack, 2 bytes

v|

Haystack is a 2D-based grid language which starts executing in the upper left-hand corner. The characters <>v^ tells the "pointer" in which direction to go. It continues in the same direction until it hits another direction identifier or the needle |.

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

DStack, 3 bytes

skt

Language created by my few days ago

\$\endgroup\$
  • \$\begingroup\$ Is there an online interpreter for this language? \$\endgroup\$ – Cows quack Nov 11 '15 at 5:34
  • \$\begingroup\$ No, the only interpreter that exists is this, the language I created it a few days ago. \$\endgroup\$ – DarkPhantom Nov 11 '15 at 5:40
1
\$\begingroup\$

Minecraft snap. Ver. 15w46a, 2 + 0 = 2 bytes

Note that this version of this "language" was created after the question was asked.

This is using this version of byte counting.

the system

Put inside of an always active repeating command block, it will, indeed, loop forever with no output.

\$\endgroup\$
  • \$\begingroup\$ might want to note that this is 1.9 only \$\endgroup\$ – anOKsquirrel Nov 12 '15 at 23:34
1
\$\begingroup\$

ShapeScript, 8 bytes

'0?!'0?!

This requires the latest version of ShapeScript, since I have just implemented tail call optimization.

The online interpreter will exit quietly after one minute. Try it online!

How it works

'       Push a string that, when evaluated, does the following:
  0?      Push a copy of the topmost item on the stack (i.e., this string).
  !       Evaluate the copy.
'
0?      Push a copy of the topmost item on the stack.
!       Evaluate the copy.
\$\endgroup\$
1
\$\begingroup\$

Thue, 11 bytes

0::=0
::=
0

(Silly 30 character minimum)

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

BASIC, 8 bytes

2 GOTO 1

A simple answer, but hey, it uses basic!

Also, for fun:

Brainf*ck, 3 bytes

+[]
\$\endgroup\$
1
\$\begingroup\$

Arcyóu, 6 bytes

(@ 1 1

While 1: append 1. Note that this will blow the stack eventually, since it's slowly building a list of 1s in memory.

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

Go, 32 bytes

surprisingly long. surprisingly, never ends.

package main;func main(){for{}}

Fun fact: compiling this, due to the go tail-call and 03- optimising compiler, this generates an executable with absent .TEXT and .DATA sections.

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

Emacs Lisp, 9 bytes

(while t)

Pretty straight-forward.

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

𝔼𝕊𝕄𝕚𝕟, 2 chars / 4 bytes

↻;

I won't add a Try it here because you probably don't want to try it.

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

ResPlicate, 5 bytes

1 4 2

After 1 step, this expands to 2 2 2 2, which is the smallest period 1 oscillator. That this is true was once the subject of a lengthy proof, which was thenceforth unceremoniously deleted when I pointed out that the fact was kind of a little bit obvious. I'm sure you can re-derive said proof yourself.

\$\endgroup\$
  • \$\begingroup\$ So it's a form of cellular automaton? \$\endgroup\$ – SuperJedi224 Jan 2 '16 at 1:13
  • \$\begingroup\$ @SuperJedi224 It's closer to being a Post canonical system. It's nearest neighbor in automaton space is probably Self-BCT, though it is not clear if the latter is usable or even Turing-complete. ResPlicate is at least an automaton with only a single state. \$\endgroup\$ – quintopia Jan 2 '16 at 1:55
1
\$\begingroup\$

STXTRM, 2 bytes

;;

Program execution in this language is... strange.

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

Dirst, 4 bytes

lpn_0

Loops as long as 0 is equal to 0.

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

GOTO, 9 bytes

M1:GOTOM1

Simply defines a label that goes to itself. GOTO seems to be Turing complete (by translation from a Minsky machine), so it should count as a programming language.

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

Sally, 20 bytes

void a a
void main a

Why the extra four bytes? First, I pipe it to sally2c, which transpiles it to C:

#include "sally.h"

/* {void -> void}: */ void apply_a(void)
{
  apply_a();
}

/* {void -> void}: */ int main(int argc, char ** argv)
{
  if(argc <= 0) { fprintf(stderr, "0 values needed"); exit(1); }
  apply_a();
  {
  }
  argv = argv;
  return 0;
}

Then, during compilation, I use the -O2 flag for tail-recursion (otherwise it segfaults), which I believe is necessary for consideration as a language.

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

RPG fixed, 133 bytes

H dftactgrp(*no) actgrp(*new)
H option(*srcstmt:*nodebugio)
H bnddir('QC2LE')
C     A             TAG
C                   GOTO      A

Basically it defines a few headers for it to compile (h-spec) and have to rows of c-specs. If it was written in free format it would have looked like this:

H dftactgrp(*no) actgrp(*new)
H option(*srcstmt:*nodebugio)
H bnddir('QC2LE')
/free
tag a;
goto a;
/end-free

Or in Perl like this:

a:;     # This is a label
goto a; # Goto that label
\$\endgroup\$
  • \$\begingroup\$ For those uncommon languages you should always add a link to an interpreter and/or show an example run of it. Otherwise no one can really judge your answer. Also an explanation of your program would improve your answer a lot. \$\endgroup\$ – Denker Feb 16 '16 at 15:35
  • \$\begingroup\$ @DenkerAffe Link to an interpreter would be hard if not impossible, as rpg is compiled on an IBM mainframe. A link to a wiki could do though. \$\endgroup\$ – andlrc Feb 16 '16 at 16:09
  • \$\begingroup\$ Thats fine. Looks a lot better now! \$\endgroup\$ – Denker Feb 16 '16 at 16:47
1
\$\begingroup\$

Condit, 2 bytes

a 

Note the trailing space. Due to what I believe is a bug, the Python 3 interpreter loops infinitely on unrecognized tokens.

\$\endgroup\$
  • \$\begingroup\$ Unless we're using different interpreters, this won't work without a trailing linefeed. \$\endgroup\$ – Dennis Feb 16 '16 at 18:05
  • \$\begingroup\$ All Unix/GNU utilities will, as their definition of line includes the linefeed. \$\endgroup\$ – Dennis Feb 16 '16 at 21:45
1
\$\begingroup\$

Puzzlang, 4 bytes

XX X

I have verified that this is, in fact, the shortest possible solution. Equivalent to +[] in BF.

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

Carriage, 7 bytes

#11-\@!

Smallest self-copying program that I could find.

\$\endgroup\$

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.