I know this might sound silly. But, what's the shortest infinite loop you can write?
Terms:
1 in a newlineUpdate your answer as you think of new one
Edit : Current shortest infinite loop @CodingCreature hashnode.com/post/can-you-write-a-shortest-infini… in fish lang with 4 chars. You can try it out here fishlanguage.com
x86 machine language... two bytes, represented as hex would look like this.
0xEB, 0xFE
If we disassemble that to assembly, we get:
jmp -2
It seems no one writes software in C anymore, although it most probably won’t win. Anyways, for the sake of completeness:
int main(){while 1 printf("1\n");)
You will get a warning from the compiler because you don’t #include <stdio.h>, but it works.
Another solution is a good old .com file for DOS. These are executed as is, pure machine code. That would probably win as it is actually executable without any fancy interpreters. I guess it would take about 10 bytes or so.
Alright, let's see.
ASM would work but move consumes 4 chars already.
I could run the code itself infinite times and print ASCII 31 0a (49 13? I guess. Idk) repeatedly. But that wouldn't be a programmatical loop.
><> (fish) works.
1n
That's it. Two chars.
Edit: I just realized, that just prints 1 repeatedly and doesn't add a newline. So..
1nao
4 chars. That should do it.
Edit2: Wait, did fish win this thing? I thought somebody would write some crazy machine-level code(which is highly unlikely; as I said, that would take 4 or more chars - just to print it) to nail this. Well, I guess ><> wins then.
You may find this helpful :D
The language is Python!! And my answer is this:
while 1:
print 1
javascriptwhile(1) document.write('1<br>')
Update (15 char):with(1)alert(1)for(;;)alert(1)
In Brainfuck:
1. >+++[->+++<]>+ incrementing third cell to 10 'LF'
2. <<+++++++[->+++++++<] incrementing second cell to 49 '1'
3. +[-+>.>.<<] looping
I will take the easy picking of PHP
<?php while (true) echo "1\n";
and for fun
<?php a: echo "1\n"; goto a;
Werner Spreeuwenberg
Ex programmer
Shortest loop would probably be in #Assembler code closest to machine language.
B B B1st B is the label of the line
2nd B is the command -> Branche (to)
3rd B is the value where to Branche to. (i.e. the same line of code)