Florian Rohrer

Posted on

# Challenge: Write a program that never stops

Write an endless loop, write some confusing gotos...

The rules are simple: Write a program that never stops. Language: Any. Try to keep it short and confusing :D

Here is an example:

``````for(i=0; i<10; i++){
for(j=0; i<10; j++){
System.out.println("Blubb.");
}
}
``````

Post your funny, creative solutions below.

Ryan Palo

Ruby:

``````loop {:D}
``````

Florian Rohrer

This gotta be the happiest loop, I've ever seen.

David Muckle • Edited
``````:(){:|:&};:
``````
``````10 PRINT "HELLO!"
20 GOTO 10
``````

Always gotta have the classics.

Ah, BASIC with manually typed line numbers and GOTO... If only the screenshot were monochromatic green or amber it would be truly classic.

David Muckle

I can do that if you'd like... dev.to/dvdmuckle/hooking-up-a-vt42... :)

Perry Ahern

That'd be cool to see, but it'd never replace my memories of flickering Commodore PET screens from days of yore. Cool write up though, saving that to read later.

Jessy
``````function a(){
a();
}

a();
``````

Endless recursivity!

Halt! 6 kere 9?

This will crash once the stack is full but nice try. :)

Arne Mertz

Use a language that allows optimization of tail recursion then ¯_(ツ)_/¯

Phoebe Goldman

Us cool kids with our tail recursion could write in, for example, Common Lisp:

``````(defun loop-for-ever ()
(loop-for-ever))
(loop-for-ever)
``````

Jessy

Hahaha yeah it totally did crash Chrome when I tried it. I wanted to just post

``````while(true){}
``````

but that's a little boring.

Halt! 6 kere 9?

Definitely classic but lacks the humor :)

Luciano Quercia
``````var f float32
for f = 0; int(f) < 16777217; f++ {
fmt.Println("Hello!")
}
``````

Kajigga

python

``````while 1:1
``````

never-ending song

``````from itertools import cycle
import time
list = ['This is the song that never ends',
'It just goes on and on my friends',
'Some people started singing it, not knowing what it was',
'And they\'ll continue singing it forever just because...']

for line in cycle(list):
print(line)
time.sleep(.25)
``````

non-stop random numbers

``````from random import randint
def infinite_random():
while True:
yield randint(1,1000000000)

for x in infinite_random():
print(x)
``````

lots of random user information

``````import requests
def get_users():
while True:
yield requests.get('https://randomuser.me/api/').json()['results'][0]

for user in get_users():
print('{0[name][first]} {0[name][last]} - born {0[dob]}'.format(user))
``````

Peter Kim Frank

The "never-ending song" is classic. 😂

Miff

Brainfuck, I guess.

``````+[]
``````

Arne Mertz • Edited

C++

``````#define ever ;;
int main() {
for(ever);
}
``````
``````int main() {
for (unsigned i = 341; i > 0; --i) {
printf("%u\n", i--);
}
}
``````
``````int main() {
float f = 1.0f;
while (f < 16777218.2f) {
printf("%f\n", f);
f += 1;
}
}
``````

assembler

``````main:
.L2
jmp .L2
``````

C

``````int main(void) {
int b=0, a[] = {0,1};
while (b != (!b)[a]) {
printf("%i\n", b=!a[b]);
}
}
``````
``````int main(void) {
https://dev.to
goto https;
}
``````

Florian Rohrer

I really like the last one. Defining a label to a comment - nice :D

Halt! 6 kere 9?

This is far the best 👍

raja sudhan

very nice friend!!

Valentin Baca • Edited

Javascript (empty statement evaluates to true so is effectively while(true)): `for(;;);`

Super-Evil Javascript DON'T RUN THIS LOL: `for(;;)alert();`

Python: `while 1:0`

Shell: `yes`
Funny story about `yes` is that in Unix it's actually just a blank file, which AT&T has the copywrite for o.0

Parth Parikh

Welcome to Verilog.

``````module tb();
always \$display("You think I will stop? Think again!");
endmodule;
``````

Karn Saheb

My god, this brings back memories that I've been trying to compartmentalize. :'(

Was missing a uninterruptible one

``````#include <signal.h>
void main(void) {
sigset_t stop;
sigemptyset (&stop);

for(;;);
}
``````

Patrik

Only to make people hate me...

HTML

`<marquee>You spin my head right round, right round...</marquee>`

Rodrigo Martins

Python

``````valuе = 0
while valuе < 1:
value = valuе + 1
``````

Python

``````i = 0
j = 10
while not i is j:
i += 1

print("i is j: " + str(i is j))

j = 257
while not i is j:
i += 1

print("unreachable")
``````

Shell command :
`yes`

Daniel Escoz • Edited

Javascript (ES6):

``````const zero = () => Promise.resolve(0).then(zero);
zero().then(result => console.log('this does not print a zero:', result));
``````

Technically ends because `.then` run on the next tick, but it permanently blocks the JS event loop (I think).

Florian Rohrer • Edited

C

``````// 1
int i = 0;
while(i < 10)
{
if(i = 5)
printf("i is 5!");
i++;
}
// 2
for(int i = 0; i < 10; i++);
{
printf("hello");
}
// 3
for(int i = 1; i < 11, i++;)
{
printf("hello");
}
``````