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>
588 Answers 588
Forth (gforth), 15 bytes
[begin] [again]
Shortened nonForgivingJesus's answer using square brackets for looping directly.
My first Forth answer!
C#9, 8 bytes
for(;;);
In C#9, they introduced Top-Level Statements which means one source file no longer needs any boilerplate.
-
2\$\begingroup\$ Welcome to the site, nice first answer! This is the shortest C# code I've seen in a while :p \$\endgroup\$2020年11月23日 20:13:03 +00:00Commented Nov 23, 2020 at 20:13
-
1\$\begingroup\$ You can just use
while 1:pass\$\endgroup\$Gleb– Gleb2024年11月05日 07:57:31 +00:00Commented Nov 5, 2024 at 7:57 -
\$\begingroup\$ Wow that was right in front of my face the whole time. Great find! For that matter while 1:1 satisfies the prompt as well. Ha looks like Ruth Franklin found this in 2015 codegolf.stackexchange.com/a/59360 \$\endgroup\$M Virts– M Virts2024年11月09日 01:05:12 +00:00Commented Nov 9, 2024 at 1:05
C(gcc, platform-independent), 17 bytes Highschooler here, finally something I can do.
main(){for(;;){}}
I read somewhere that this is the least bytes for an infinite loop, although I'm not sure.
-
\$\begingroup\$ The least bytes is a 0-byte C program compiled with GCC-EFI. \$\endgroup\$Makonede– Makonede2021年05月11日 20:49:55 +00:00Commented May 11, 2021 at 20:49
-
\$\begingroup\$ I believe you can replace the
{}for the loop body by a single semicolon;\$\endgroup\$ecm– ecm2021年12月25日 16:29:41 +00:00Commented Dec 25, 2021 at 16:29 -
\$\begingroup\$ @Makonede wait THAT was possible? \$\endgroup\$dnn25519– dnn255192021年12月26日 13:54:33 +00:00Commented Dec 26, 2021 at 13:54
Jellyfish, 5 bytes
\>1
1
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.
x86 machine code - 2 bytes
6 .loop:
7 00000000 EBFE jmp .loop
This is a same code as :
6 00000000 EBFE jmp $
x86_16 machine code - 2 bytes
12 0005 EB FE JMP $
Tested on DOSBox
-
\$\begingroup\$ Fun fact: Typing this in Unicode yields
ëþ. These letters (AFAIK) don't have a common language, but pronouncing them how they normally would be in their respective languages yields "yohth", which sounds sort of like a British person with a lisp trying to say "yours". :P \$\endgroup\$Makonede– Makonede2021年06月08日 21:41:37 +00:00Commented Jun 8, 2021 at 21:41
Knight, 3 bytes
W1N
# pretty straightforward
WHILE 1
# The official name for this builtin is NULL.
# Because builtins are determined by the
# first character, I can call it NOP.
NOP
h, 20 bytes
8,2,9,4,9,6,8,2,-1,0
Neither the language (by Nerdaxe) nor this answer (by VilgotanL) are my creations, but I want to publicize them here.
h (link) is a programming language created by Nerdaxe which is quite limited.
Here's an explanation of how the program works through pseudocode similar to subleq assembler:
neg1 2 #acc is now -1
zero 4 #acc is now 1, the variable zero is 1
zero 6 #acc is now 0, the variable zero is 0
neg1 2 #acc is now -1, go back to 2
neg1:-1 zero:0 #variables
Daoyu, 1 byte
><
Each instruction is one hex, so two instructions fit into one byte (0x69). The < increases the operating level (a number that affects certain commands) and moves the program reader to the beginning of the program, but only if the op level is less than 9. So, it's preceded by the > command, which decrements the op level (to a minimum of zero).
Minim, 4 Bytes
C--.
Decrements the program counter, which is incremented back to 0 after the statement finishes.
Plumber, 7 bytes
[]
[[]]
This is the shortest possible infinite loop in Plumber.
Plumber programs are divided into units, which are always two characters wide (and padded to two with spaces if shorter). This one consists of three units: [], [[, and ]]. When a Plumber program is run, a 0 packet is dropped from all [] on the top row. This packet can be picked up by a ][, which pushes it to the sides.
A [[ will push it to the right, but it continues down (and is destroyed upon leaving the 2d space). Likewise, when the ]] is pushed into from either side (left in thus case), the packet is dropped and destroyed, and pushed back to the left. The [[ pushes it back to the ]], and this continues indefinitely.
BitCycle, 3 bytes
1><
Explanation (because i can)
1 Creates a 1 bit, heading east by default
> Sets the direction to east
< Sets the direction to west
> Sets the direction to east again, creating a loop
-
\$\begingroup\$ this has already been posted btw \$\endgroup\$naffetS– naffetS2022年08月05日 03:04:41 +00:00Commented Aug 5, 2022 at 3:04
-
\$\begingroup\$ @Steffan Should I delete it? \$\endgroup\$97.100.97.109– 97.100.97.1092022年08月05日 03:06:34 +00:00Commented Aug 5, 2022 at 3:06
-
\$\begingroup\$ No need to. \$\endgroup\$naffetS– naffetS2022年08月05日 03:07:42 +00:00Commented Aug 5, 2022 at 3:07
-
1\$\begingroup\$ No need to mark it as non-competing. :) That isn't a thing anymore since 2017. This challenge also explicitly allows newer languages in the challenge description: "Feel free to use a language (or language version) even if it's newer than this challenge." \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2023年04月17日 11:51:55 +00:00Commented Apr 17, 2023 at 11:51
-
\$\begingroup\$ @KevinCruijssen I didn't know that, thanks! \$\endgroup\$Peter– Peter2023年04月17日 12:51:50 +00:00Commented Apr 17, 2023 at 12:51
Tsept v1.0, 5 bytes
Tsept is an esolang I created; it's not good at golfing since even basic tasks like storing numbers and printing strings require a lot of instructions.
This program is 5 bytes long because it has to calculate and repeatedly push the jump offset.
xDDPJ
Note: Due to a bug in the interpreter, the 'J' instruction jumps to the wrong offset (specifically the original offset plus one).
'x' clears the value in the accumulator since, at the start, it contains the interpreter's version.
'D' decrements the interpreter, and due to the aforementioned bug, it has to do it twice.
'P' pushes the accumulator onto the stack.
'J' pops a value from the stack and adds it to the instruction pointer, effectively performing a relative jump.
CASIO BASIC (CASIO fx-9750GIII), 4 bytes
Lbl A
Goto A
Regenerate, 3 bytes
1ドル+
Outputs the smallest nonzero number of repetitions of a backreference to the first capture group for which the first capture group has actually captured something. Unfortunately for the poor unsuspecting interpreter, the first capture group doesn't even exist.
-
1\$\begingroup\$ What about
while(1){}? \$\endgroup\$user63571– user635712017年01月30日 17:58:15 +00:00Commented Jan 30, 2017 at 17:58 -
1\$\begingroup\$ The condition needs to be a
Bool, sowhile(1)wouldn't compile. You probably can save 1 byte by removing the parens around the condition:while 1>0{}\$\endgroup\$Tiziano Coroneo– Tiziano Coroneo2019年08月07日 10:56:59 +00:00Commented Aug 7, 2019 at 10:56
Rust, 17 chars
fn main(){loop{}}
Nothing much interesting to see here.
FlogScript, 6 bytes
This creates a string containing code for duplicating the top value on the stack, then popping it and executing it as code. Then it is duplicated, popped, and executed as code.
{.~}.~
CoffeeScript, 6 bytes
loop 0
Interesting fact thanks to Martin Büttner, not sure if there's any practical use to it though.
Previous attempt (8 bytes):
1while!0
There is only a while loop, no for (though there are for..in and for..of).
-
\$\begingroup\$ CoffeeScript actually has a keyword for infinite loops:
loop 1\$\endgroup\$Martin Ender– Martin Ender2015年10月02日 19:19:43 +00:00Commented Oct 2, 2015 at 19:19
Basilisk, 5 bytes
:A1gA
Pretty simple.
Explanation
:A
Defines position A.
1gA
Pushes one and goes to position A in code. Since the gA pops the top value in stack, if the loop were ever to end, it would not print anything.
STATA, 10 bytes
while 1{
}
Apparently for loops in STATA always halt, but while loops can be infinite.
-
\$\begingroup\$ Is the line break needed? I've never used STATA \$\endgroup\$Albert Renshaw– Albert Renshaw2016年05月12日 20:14:21 +00:00Commented May 12, 2016 at 20:14
-
1\$\begingroup\$ @AlbertRenshaw The line break is required, and it will throw a syntax error if it is not there. See stata.com/manuals13/pwhile.pdf#pwhile for details. \$\endgroup\$bmarks– bmarks2016年05月17日 14:19:31 +00:00Commented May 17, 2016 at 14:19
-
\$\begingroup\$ What about
a: goto a? :D 9 bytes —— stata.com/manuals14/m-2goto.pdf \$\endgroup\$Albert Renshaw– Albert Renshaw2016年05月17日 17:42:37 +00:00Commented May 17, 2016 at 17:42 -
\$\begingroup\$ In-fact, the space after
a:might not be needed, I don't have STATA so I can't test but I'd imagine it's possible to omit the space and get it down to 8 bytes \$\endgroup\$Albert Renshaw– Albert Renshaw2016年05月17日 17:44:04 +00:00Commented May 17, 2016 at 17:44
"", an empty string? \$\endgroup\$