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

12
\$\begingroup\$

PowerShell, 7 bytes

for(){}

...

\$\endgroup\$
  • 1
    \$\begingroup\$ Heh. Beat my own attempt by three bytes. Learned a couple of things from this challenge! \$\endgroup\$ – Booga Roo Oct 4 '15 at 20:38
  • 1
    \$\begingroup\$ Quickly writes code. Starts scrolling to post...oh... for(){} same \$\endgroup\$ – Chad Baxter Oct 6 '16 at 14:21
11
\$\begingroup\$

Funciton, 72 bytes

Encoded in UTF-16.

I cannot think of a smaller Funciton program that would run forever. It consists of a declaration of a function that calls itself and a main program that calls said function on STDIN. Is it possible to do shorter?...

┌─╖╓─╖┌─╖╔╗
┤∞╟╢∞║┤∞╟╢║
╘═╝╙─╜╘═╝╚╝
\$\endgroup\$
  • \$\begingroup\$ Well, it looks like this only takes 35 bytes in cp437, and according to Python it actually round-trips. Does that count as shorter? \$\endgroup\$ – SamB Sep 21 '18 at 22:07
  • 1
    \$\begingroup\$ @samb The interpreter doesn't accept cp437-encoded files. \$\endgroup\$ – Timwi Oct 10 '18 at 12:14
10
\$\begingroup\$

Matlab/Octave, 11 bytes

while 1;end

(tested)

\$\endgroup\$
  • \$\begingroup\$ It works. You can remove the untested warning. +1. \$\endgroup\$ – rayryeng Oct 2 '15 at 22:32
  • \$\begingroup\$ Did you test it in Matlab and Octave? (Oh and I just noticed: Tested says nothing about the outcome of the test=)) \$\endgroup\$ – flawr Oct 2 '15 at 23:03
  • 2
    \$\begingroup\$ Yes they both work... Well... It halts :) if that's what you're looking for. \$\endgroup\$ – rayryeng Oct 2 '15 at 23:05
10
\$\begingroup\$

A POSIX OS's program loader, 14 bytes

#!/usr/bin/env
\$\endgroup\$
  • \$\begingroup\$ How do you run this? \$\endgroup\$ – Alex A. Oct 3 '15 at 0:47
  • \$\begingroup\$ The space isn't necessary. \$\endgroup\$ – jimmy23013 Oct 3 '15 at 1:46
  • \$\begingroup\$ @AlexA. Save as t, make executable (chmod +x t) and execute (./t). \$\endgroup\$ – Dennis Oct 3 '15 at 1:47
  • 1
    \$\begingroup\$ @xebtl: With this in /tmp/foo, the execve(/tmp/foo) -> OS invokes /usr/bin/env as the interpreter, with argv[0] = /tmp/foo. This causes env to execve(/tmp/foo). Try it with strace -f -eexecve /tmp/foo. The Linux man page for env(1) doesn't seem to mention the case where env is invoked with it's 0th arg being something other than env, but it's standard behaviour. I guess env figures out when it's being used as an interpreter for stuff like #!/usr/bin/env perl to use $PATH to find perl. So in that case, it processes anything on the line as env args, then appends $0. \$\endgroup\$ – Peter Cordes Oct 6 '15 at 0:31
  • 1
    \$\begingroup\$ Putting #!/tmp/f in /tmp/f results in execve returning an error: ELOOP. Even if that did work, you'd have to count the string twice: once in the file, and once as the required filename. (although /f would work, and maybe even a single-char relative path). But anyway, not viable. \$\endgroup\$ – Peter Cordes Oct 6 '15 at 0:32
9
\$\begingroup\$

Recall, 2 bytes

Yy

Since there is no break operator, it will loop forever. You can try it here. Of course it will freeze the tab.

\$\endgroup\$
9
\$\begingroup\$

Pyth, 2 bytes

I think the only solutions are '# ', which has already been posted, and the f based solutions:

f0
fk
fH
fY
fZ
f"
f[
f(
f{
f]

f followed by anything falsy.

\$\endgroup\$
  • \$\begingroup\$ Thanks, I hadn't noticed that one. I'll remove it. @Dennis \$\endgroup\$ – isaacg Oct 3 '15 at 20:53
8
\$\begingroup\$

GolfScript, 3 bytes

1do

For obvious reasons, this does not work in the online interpreters.

\$\endgroup\$
  • \$\begingroup\$ Shame this has got only 2 upvotes after over a year, it deserves more... \$\endgroup\$ – Erik the Outgolfer Nov 12 '16 at 10:47
8
\$\begingroup\$

C, 17 bytes

main(){l:goto l;}

Why not for(;;);? Because goto are cool.. and 17 is a nice number

\$\endgroup\$
  • 5
    \$\begingroup\$ -1, intentionally not as short as possible. main(){for(;;);} is one byte shorter, at 16B. \$\endgroup\$ – Peter Cordes Oct 6 '15 at 21:15
  • \$\begingroup\$ @PeterCordes Why not main(){main();}? \$\endgroup\$ – Alchymist Oct 21 '15 at 15:09
  • 2
    \$\begingroup\$ Hi @PeterCordes. For it to work, I needs to pass an option to the compiler.. so I decide to go pure C. Check Mark's solution at the first page of this codegold, where he proposes main(){main();}. \$\endgroup\$ – wendelbsilva Oct 21 '15 at 16:15
8
\$\begingroup\$

Microchip PIC Machine Code, 0 bytes

An unprogrammed/erased PIC will by default have the program memory (flash) contain all NOP instructions. NOP does nothing.

Now, NOPs by themselves don't implement infinite loop. But the PIC program counter by design wraps around back to zero. Therefore, an unprogrammed/erased PIC executes an infinite loop.

Note: This is true for a lot of CPU architectures. Especially microcontrollers.

\$\endgroup\$
  • \$\begingroup\$ Interesting. For reference, on x86: 00 00 is add [eax], al. (or rax for 64bit code.) So it will segfault unless eax happens to hold a valid pointer. \$\endgroup\$ – Peter Cordes Oct 6 '15 at 0:43
  • \$\begingroup\$ @PeterCordes: Depending on the CPU family, erased EEPROM can have values of either 0xfff or 0xffff (PICs have weird word length for program memory - like 12 bits or 10 bits etc.). But it is always interpreted as NOP. A segfault triggers an interrupt right? So if the interrupt handler for segfault is also null it would continuously re-segfault. Isn't that a loop? \$\endgroup\$ – slebetman Oct 6 '15 at 2:56
  • \$\begingroup\$ Oh right, so EEPROMs are like NAND flash, and erase to one, not zero. Neither 0F FF nor FF FF are valid instructions in x86 machine code, in 16, 32, or 64bit mode. In Unix, a segfault results in a SIGSEGV signal being delivered to the process by the OS. An illegal instruction results in a SIGILL. The default action is to terminate the process. If the process had earlier installed a signal handler (with the sigaction(2) system call), it could catch SIGSEGV or SIGILL. It's a much better design to default to killing processes that run bad code, vs. inf loop! \$\endgroup\$ – Peter Cordes Oct 6 '15 at 20:26
  • 1
    \$\begingroup\$ @PeterCordes: I'm talking about a bare x86 CPU with all the data pins soldered to ground - it won't be able to load any OS but it should permanently segfault. Though I wonder, if you need to add 1 byte for every command line flag passed to the interpreter how many points do you need to add if you solder the pins on the CPU? \$\endgroup\$ – slebetman Oct 6 '15 at 20:58
  • \$\begingroup\$ Oh right, of course you wouldn't have an OS on unprogrammed memory. But it's only a "segfault" if you're running under a Unix-like OS. You're talking about a #GP(0) general-protection fault or #UD undefined insn fault. The only way a bare CPU will actually "stop" is if you run some kind of halt-until-next-interrupt instruction. The default behaviour is to keep running, even if it's a loop of illegal-instructions in the illegal-instruction-handler. I'd consider a fault to be the hardware running your program again, rather that the prog being a loop, and thus less interesting. \$\endgroup\$ – Peter Cordes Oct 6 '15 at 21:22
8
\$\begingroup\$

Turing Machine Code, 9 bytes

As usual, I'm using the rule table syntax defined here.

0 _ _ * 0

"When in state 0, upon reading an empty cell, replace it with an empty cell, don't move, and transition to state 0."

\$\endgroup\$
8
\$\begingroup\$

C, 11 bytes (on old x86)

main=65259;

65259 or 0xfeeb is the machine code eb fe or jmp -2. Jumps are relative to the next instruction, so this loops.

This compiles (with a warnings) and works on my Linux 2.4.9.
Newer Linux will usually put main in a non-executable section. Adding const will fix it, but at an unbearable price.

Just noticed kirbyfan64sos's answer that uses the same machine code. But it's not in C.

\$\endgroup\$
7
\$\begingroup\$

Macaroni 0.0.2, 14 chars

label a goto a

Fairly self-explanatory...

\$\endgroup\$
  • 1
    \$\begingroup\$ -1 because you wrote Macaroni in Rust, and I don't have Rust right now, so I can't use it. :( (jk, I actually upvoted.) \$\endgroup\$ – kirbyfan64sos Oct 5 '15 at 21:37
7
\$\begingroup\$

VBA (immediate pane), 14 bytes

This will freeze up the VBE and its host app:

do:loop
\$\endgroup\$
  • \$\begingroup\$ 1:goto 1 beat me by one... \$\endgroup\$ – RubberDuck Oct 5 '15 at 22:16
  • \$\begingroup\$ I think this is only 7 bytes, why did you say 14? \$\endgroup\$ – SuperJedi224 Feb 14 '16 at 12:30
  • \$\begingroup\$ @SuperJedi224 I wasn't sure if the IDE itself was like that, but VBA strings are 2 byte per character, ..I went for the worst-case figure :-) \$\endgroup\$ – Mathieu Guindon Feb 14 '16 at 14:11
7
\$\begingroup\$

Malbolge, 1 byte

 

A single-space program causes Ben Olmstead's reference implementation to loop forever. Can you find out why?

\$\endgroup\$
  • 1
    \$\begingroup\$ Wouldn't this be UF, looking for indices -1 and -2 of mem? \$\endgroup\$ – LegionMammal978 Oct 25 '15 at 11:27
7
\$\begingroup\$

Mouse, 5 3 bytes

()$

This is just a simple "while true do nothing."

Saved 2 bytes thanks to cat.

\$\endgroup\$
  • 14
    \$\begingroup\$ So, what you're saying is that Cat took two bytes out of Mouse, but didn't eat the whole thing? \$\endgroup\$ – Steve Eckert Jan 12 '16 at 13:56
  • \$\begingroup\$ @SteveEckert Haha. :D \$\endgroup\$ – HyperNeutrino May 1 '16 at 22:36
7
\$\begingroup\$

Chef, 75 52 46 bytes

Saved 23 bytes thanks to @Sp3000

L.

Ingredients.
1 i

Method.
X i.M until xed.

Try it online! (if you dare)

Basically, this program repeatedly checks that i (always 1) is greater than zero, and while it is, Ms the empty mixing bowl. I tried to stick to the original spec as much as possible, so it may be able to golf this even more. Thanks to TIO, I can now verify my changes with a copy of the interpreter!

\$\endgroup\$
  • \$\begingroup\$ The add actually breaks it because you never put anything into the bowl. Note that verb the ingredient checks the ingredient itself, rather than the mixing bowl, so you can just drop the add altogether. Other golfs 1) Drop g from 1 g i 2) Replace Mix like you say, e.g. X the i.Mix until xed 3) Serves is optional \$\endgroup\$ – Sp3000 Oct 5 '15 at 7:38
  • \$\begingroup\$ @Sp3000 O great Resident Chef Master, thanks for your input! It's now down to 52 bytes. \$\endgroup\$ – ETHproductions Oct 5 '15 at 16:58
6
\$\begingroup\$

X86/X64 Machine Code, 2 bytes

Hex dump:

0xEB 0xFE

Disassembled source code:

f:jmp f

Basically, because the entry point _start isn't defined, ld defaults to the address that is coincidentally the location of f.

\$\endgroup\$
  • 1
    \$\begingroup\$ In some dialects of assembly you can write this as jmp . or jmp $ without a label. \$\endgroup\$ – Random832 Oct 2 '15 at 22:56
  • \$\begingroup\$ @Random832 The exact same machine code is generated, though, so it doesn't mean anything. \$\endgroup\$ – kirbyfan64sos Oct 2 '15 at 23:10
  • 2
    \$\begingroup\$ I stuck these 2 bytes into a malformed ELF header to produce a 45 byte executable program codegolf.stackexchange.com/a/59479/19694 \$\endgroup\$ – casey Oct 3 '15 at 3:33
  • \$\begingroup\$ On DOS, you could put just those two bytes in a .COM file. \$\endgroup\$ – celtschk Oct 4 '15 at 11:54
  • 1
    \$\begingroup\$ @casey: If you're interested in ASM source size, I posted a 4-byte x86 YASM/NASM answer, which works on Linux: ja $. I included an explanation of how it works as a complete program. \$\endgroup\$ – Peter Cordes Oct 6 '15 at 21:11
6
\$\begingroup\$

JavaScript, 8 bytes

NOTE: This is the same as the existing Processing answer; just posting it for the sake of catalogue completeness.

for(;;);

Bonus: Here's a 12-byte ES6 alternative, using recursion instead:

a=_=>a();a()
\$\endgroup\$
  • 1
    \$\begingroup\$ For the JavaScript version you can drop the final semicolon to save a byte ;-) \$\endgroup\$ – scunliffe Oct 3 '15 at 3:10
  • 3
    \$\begingroup\$ @scunliffe No, you can't. Just paste for(;;) into your browser console if you don't believe me. (The reason is that a for loop must execute at least one statement, even if it's an empty one.) \$\endgroup\$ – user2428118 Oct 3 '15 at 12:29
  • \$\begingroup\$ @scunliffe Yes, I actually tried that, but as user2428118 pointed out, it doesn't work. \$\endgroup\$ – ETHproductions Oct 3 '15 at 19:12
  • \$\begingroup\$ isnt this a standart loop? \$\endgroup\$ – Alex Oct 9 '15 at 12:57
  • 1
    \$\begingroup\$ @Alex Um, yes, it's a standard JS loop. Is there something wrong with that? Or did you mean standard loophole? \$\endgroup\$ – ETHproductions Oct 9 '15 at 16:22
6
\$\begingroup\$

APL, 8 5 4 bytes

-⍣=1

This repeats negation until the result is equal to the previous input (beginning at 1) which can't happen, so it loops indefinitely.

Saved 3 bytes thanks to Dennis and 1 thanks to jimmy23013!

\$\endgroup\$
  • \$\begingroup\$ s/forever/until the stack overflows \$\endgroup\$ – kirbyfan64sos Oct 2 '15 at 19:52
  • \$\begingroup\$ @kirbyfan64sos Hah, good point. \$\endgroup\$ – Alex A. Oct 2 '15 at 19:55
  • \$\begingroup\$ Or -⍣=1 . \$\endgroup\$ – jimmy23013 Oct 3 '15 at 0:30
  • \$\begingroup\$ @jimmy23013 I don't understand that code. What does it do? \$\endgroup\$ – Alex A. Oct 3 '15 at 0:32
  • \$\begingroup\$ Repeat negation until the result is the same as the input. \$\endgroup\$ – jimmy23013 Oct 3 '15 at 0:33
6
\$\begingroup\$

Unlambda, 7 bytes

``ci`ci

Try it here. It uses c (call-cc) which is a little magical.

\$\endgroup\$
  • 1
    \$\begingroup\$ A little magical? :-) \$\endgroup\$ – celtschk Oct 4 '15 at 12:00
6
\$\begingroup\$

Starry, 9 bytes

`      +'

Loops in Starry are written with ` (which marks the current location in the code as label n, where n is the number of spaces in front of it) and ' (which pops a value from the stack and jumps to label n if that value was non-zero). So we use these two n = 0. But that leaves the question how to get a non-zero value onto the stack. I believe the shortest way to do is simply to push a 1, which requires 6 spaces and a +.

\$\endgroup\$
6
\$\begingroup\$

PHP, 8 bytes

for(;;);

When running from command line (-r argument) you don't need php openning/closing tags.

Ex.: php -r "for(;;);"

\$\endgroup\$
  • 3
    \$\begingroup\$ This produces an error PHP Parse error: syntax error, unexpected end of file in Command line code on line 1 or Parse error: parse error in Command line code on line 1 depending on the PHP version used and when run like php -r "for(;;)". You need at least one additional ; at the end. \$\endgroup\$ – insertusernamehere Oct 2 '15 at 22:00
  • 6
    \$\begingroup\$ Rule 1: Each submission must be a full program, in this case <?for(;;);. \$\endgroup\$ – primo Oct 3 '15 at 4:20
  • \$\begingroup\$ @primo this is a full program \$\endgroup\$ – NieDzejkob Mar 15 '18 at 17:07
6
\$\begingroup\$

Mornington Crescent, 117 106 Bytes

Take Northern Line to Bank
Take Circle Line to Temple
Take Circle Line to Bank
Take Northern Line to Angel

There appear to be some bugs in the Python interpreter, but the language's creator has a C# interpreter that works for this code.

*Inspired by @ETHproductions

EDIT: Since it doesn't ever terminate, can remove required return to Mornington Crescent

Thanks Martin Büttner for 8 bytes, and Timwi for 3 bytes.

\$\endgroup\$
  • \$\begingroup\$ Using Bank instead of Moorgate saves 8 bytes. (My prime tester answer has a CJam script that helps when finding the shortest path between two stations.) \$\endgroup\$ – Martin Ender Oct 7 '15 at 14:34
  • \$\begingroup\$ Esoteric IDE does not require Windows EOL. I saved your program with UNIX line endings and the IDE opens and interprets it fine. :) \$\endgroup\$ – Timwi Oct 7 '15 at 14:42
  • 2
    \$\begingroup\$ @MartinBüttner Yes, should have looked at the actual code, instead of the London tube map :P \$\endgroup\$ – Fongoid Oct 8 '15 at 13:49
  • 5
    \$\begingroup\$ I love the fact that ^that comment was able to happen. "I would have been able to make this code shorter but I was looking at the London tube map." \$\endgroup\$ – undergroundmonorail Oct 8 '15 at 14:11
  • \$\begingroup\$ @undergroundmonorail Username checks out ;) \$\endgroup\$ – ThreeFx Sep 10 '16 at 15:18
6
\$\begingroup\$

Piet, 2 Codels

2 Codels is as small as a loopy Piet program gets.
With only 1 codel the 8 waits needed for a finish would be immediatly met.

2 codel loopy Piet

In the example (10 pixel codelsize) the difference between the 2 colours are +2/-2 Hue delta and +2/-2 Light delta. So it keeps on repeating a "roll" "not".

\$\endgroup\$
5
\$\begingroup\$

Ruby, 6 bytes

Pretty self explanatory. Ok, my post is long enough now.

loop{}
\$\endgroup\$
  • 1
    \$\begingroup\$ And I came here thinking I could win with (1..1.0/0).all?. \$\endgroup\$ – Cyoce Apr 16 '16 at 22:08
  • \$\begingroup\$ same for rust lol \$\endgroup\$ – Chromium Jun 25 '18 at 10:31
5
\$\begingroup\$

Processing, 8 bytes

for(;;);


This is based on Geobit's answer in Java


Although the code below is not the shortest, it is one of Processing's specialties.

void draw(){}

This draw statement repeats itself over and over again. It is one of the differences between Processing and Java.

\$\endgroup\$
  • 4
    \$\begingroup\$ You can also add JavaScript to your title, code stays the same=) \$\endgroup\$ – flawr Oct 2 '15 at 18:11
5
\$\begingroup\$

CJam, 4 bytes

1{}h

Put a 1 on the stack, and loop until 1 is no longer truthy. Using h means that the number is never popped.

\$\endgroup\$
  • 5
    \$\begingroup\$ Alternatively, {1}g. \$\endgroup\$ – Martin Ender Oct 2 '15 at 19:01
5
\$\begingroup\$

Beam, 2 bytes

There is a few ways of doing this from the very basic

><

to the very basic

>?

and

>|
\$\endgroup\$
  • \$\begingroup\$ I just came over here to post this, but then I noticed it in the catalogue snippet. +1 \$\endgroup\$ – ETHproductions Oct 2 '15 at 22:41
5
\$\begingroup\$

AWK, 12 bytes

END{for(;;)}

Does nothing with each line of input, then hangs forever at the end.

\$\endgroup\$
  • \$\begingroup\$ This actually requires input. So it will wait forever before entering the loop, if nothing is input. If waiting forever counts, then 0 is the shortest code. Since it is a label, which requires input, but it also won't print anything. \$\endgroup\$ – Robert Benson Apr 11 '17 at 13:49
5
\$\begingroup\$

MarioLANG, 3 bytes

!
=

I found several other solutions, but they seem to be bugs in the Ruby interpreter rather than features of the language (e.g. replacing ! with @). This one actually seems to work intentionally. = is just a ground cell for Mario to stand on, and ! instructs him to stop walking. So he just stands there, waiting for something to happen, which of course doesn't. (The usual purpose of ! is to use it on elevators, such that Mario remains in place while the elevator moves to its target position.)

\$\endgroup\$
  • \$\begingroup\$ This doesn't work on tryitonline i guess that it consider the program finished since mario is not moving at all, the next intuitive solution ' ^=' (marioLANG ain't easy to do in comment :/) doesn't work either \$\endgroup\$ – Ether Frog May 24 '16 at 19:54
  • \$\begingroup\$ @EtherFrog I think TIO uses a different interpreter than the Ruby interpreter I tested this with. \$\endgroup\$ – Martin Ender May 24 '16 at 21:28

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.