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

568 Answers 568

0
\$\begingroup\$

Chip-8, 1 byte

0x12

Instructions in Chip-8 are 2 bytes, so 0x12 is interpreted as 0x1200 (assuming the unused parts of the program are filled with zeros)

Instruction 0x1... jumps to the address stored in the lower 1.5 bytes, which is 0x200, the start of program memory.

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

Stax, 1 byte

W

Try it online!

Just an unconditional loop without body.

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

axo, 1 byte

_

Try it online!

_  goes to the command at 0,0, which happens to be _
\$\endgroup\$
0
\$\begingroup\$

uBASIC, 7 bytes

1Goto1:

Try it online! Version that produces output may be seen Here

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

VBA, 7 Bytes

Anonymous VBE immediate window that takes no input and loops forever

Do:Loop 
\$\endgroup\$
0
\$\begingroup\$

Yabasic, 7 bytes

Anonymous Function that takes no input and loops forever.

Do:Loop

Try it online! A version that infinitely outputs 1 may be seen here.

\$\endgroup\$
1
  • \$\begingroup\$ You might as well combine this answer with your VBA answer, given that they're identical. \$\endgroup\$ Feb 12, 2018 at 20:37
0
\$\begingroup\$

MY-BASIC, 12 bytes

Anonymous While loop that loops forever.

While 1
Wend

Try it online! A version that prints 1 infinitely may be seen here.

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

Visual Basic .NET (.NET Core), 44 bytes

Declare Subroutine that takes no input and loops forever.

Module M
Sub Main
Do
Loop
End Sub
End Module

Try it online! A version that outputs 1 infinitely may be seen here.

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

PHP 7, 8 bytes

for(;;);

This is the shortest I could think of, it's one shorter then

while(1);
//and
a:goto a;

Try it online

it's 5 more if you count the <?php tag

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

Wumpus, 0 bytes

Try it online!

Another 0 byte 2D entry. In Wumpus, the first cell is implicitly created, the pointer is always out of bounds, so it reflects forever.

\$\endgroup\$
1
  • \$\begingroup\$ I'd have to double check the code, but I think the first cell isn't actually created. Instead the grid has dimensions 0x1 so that the IP is always out of bounds (and then still bounces around the edges of its current OOB cell forever). \$\endgroup\$ Feb 13, 2018 at 10:03
0
\$\begingroup\$

Pain-Flak, 8 bytes

))((})({

Try it online!

Explanation:

))(( pushes 1 on stack
})({ the }...{ loops until TOS = 0 and the )( makes it run as a loop because without the )( the }...{ would eval as }{ and not loop
The code is flipped and added to the end during Pain-Flak interpreting and the code does a infinite loop again. 
\$\endgroup\$
1
  • \$\begingroup\$ Note I found the Brain-Flak answer after I wrote this. This was not just a cheap port :P \$\endgroup\$
    – user63187
    Mar 1, 2018 at 19:12
0
\$\begingroup\$

So I suppose I can create a new language and develop its intepreter for this answer, can't I?

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

Ghrvy...!, 3 bytes

grv

Intepreter written in Python 3

Explanation first (Syntax and functions please see below)

g            # Add 1 to the 1st cell
 r           # Loop when 1st cell != 0
  v          # Switch between cell manipulation and pointer manipulation
             # Implicit end of loop. Since 1st cell is still 1, voilà, infinite loop.

Ghrvy...! is a new programming language developed just after I finished golfing my answer in the challenge Non discriminating programming that I at first typed a lot of ghrvys in the code to meet the requirements. Since it is inspired by brainfuck, it is also the type of cell-pointer esolang. All programs in brainfuck can be transpiled to this language.

Syntax:

`g`: aGaru  - increase the pointer / value in current cell by 1.
              Affects the value by default.
              (Japanese for 'going up')
`h`: Heru   - decrease the pointer / value in current cell by 1.
              Affects the value by default.
              (Japanese for 'becoming less')
`r`: Repeat - repeat the next code block (block with indent 
              greater than the indent of the line where the `r` 
              token is on) if r is the last command of the same 
              line, or else repeat the remaining code on the same 
              line, when the value in current cell is non-zero.
`v`: Value  - switch the target of tokens `g` and `h` between the
              pointer and the value at the pointer.
`y`: Yee    - Set the value in current cell to a random number in
              the range [0, value in next cell] inclusive.
`.`: Input  - Get a byte from user input and set the value in
              current cell to that byte. Supports UTF-8.
`!`: Output - Output value in current cell as a byte in UTF-8. 
              The program will wait for a valid UTF-8 
              representation to output.
Spaces(` `) - No meaning when between commands on a line, act as
              indentation when at the beginning of a line.
Newlines    - Split code blocks, no meaning.

Since there must be something after the token r and token v does no pointer , cell and I/O manipulations, the program grv can be transpiled to brainfuck as +[].

Messages in the STDERR generated are those generated by the intepreter. No actual output is generated by the Ghrvy...! program itself.

Well, I came up the idea of the language first, and found this challenge may be a good place to show the features ;)

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

Sceql, 3 bytes

Make the current byte non-zero, then loop forever. I use this implementation to verify it.

-\/
\$\endgroup\$
0
\$\begingroup\$

Python 3, 37 bytes

Hope I did this correctly

try:
    while 1:pass
except:pass

Try/Except will end program when memory runs out.

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

Dreaderef, 5 bytes

1 9-1

Try it online!

Explanation

deref 9 -1 ; put value of cell 9 (initially 0) into cell -1, the instruction pointer

The 9 could have been replaced with any integer except -1, 0, or 2.

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

Reflections, 5 bytes

v\
\/

Test it!

Explanation:

  • v reflects the IP down
  • \ reflects the IP right
  • / reflects the IP up
  • \ reflects the IP left
  • v reflects the IP down into the loop again
\$\endgroup\$
0
\$\begingroup\$

Japt, 1 byte

Assumes an unlimited call stack.

ß

Test it

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

MachineCode, 5 4 bytes

ebfe

This executes the machine code EB FE (JMP -2); -2 (0xFE) is the length of the instruction.

Try it online!

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

Tamsin, 10 bytes

main={''}.

Try it online!

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

Idris, 19 bytes

main:IO()
main=main

Haskell solution + type signature.

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

ink, 7 bytes

-(i)->i

Try it online!

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

Crystal, 6 bytes

loop{}

The loop keyword takes a block, which is here denoted by the curly brackets. I'm not sure I've seen any "real" (intended for use) Crystal code that uses loop instead of while, but I'd expect it to be used in the expanded form:

loop do
  # do something here
end
\$\endgroup\$
0
\$\begingroup\$

Aheui, 0 byte.

Since Aheui is befunge-like, this is infinite loop.

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

VTL-2, 7 bytes

2 #=1

# is the system variable in VTL-2 for line numbers, and it works to retrieve a line number or as a GOTO if given an assignment. So this is a trivial GOTO loop. The one interesting thing about it is that VTL-2 doesn't actually let you GOTO the current line number. It does GOTO the next largest line number when given a nonexistent line, however, so a one-line infinite loop will always work given that y is less than x for the program x #=y.

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

33, 4 bytes

Yes, this is a very simple answer:

1a[]

Nothing short of outright hardware failure will stop this from running. Or, y'know, stopping the program.

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

Forget, 37 bytes

const 0x0 1;cleanse 0x0;while 0x0;end

TIO

\$\endgroup\$
2
  • \$\begingroup\$ What makes this non-competing? Languages created after the challenge are allowed. \$\endgroup\$ Aug 7, 2019 at 8:26
  • \$\begingroup\$ @TheOnlyMrCat I guess things have changed \$\endgroup\$ Aug 7, 2019 at 17:08
0
\$\begingroup\$

GOLANG : 32 Bytes

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

One more solution :

package main;func main(){for{}}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to Code Golf! You can eliminate two of the spaces. Try it online! \$\endgroup\$
    – Dennis
    Aug 7, 2019 at 13:18
0
\$\begingroup\$

Oasis, 2 bytes

1b

TIO

Explanation

1  Starting from a(1)
 b Recurse all the way down (i.e. do a(n-1))
\$\endgroup\$
0
\$\begingroup\$

Stax, 1 bytes

G

Run and debug it

G goes to the beginning of the program...

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

ABC (Esoteric), 1 byte

l

Loops back to the beginning.

\$\endgroup\$

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.