DEV Community

Florian Rohrer
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.");
    }
}
Enter fullscreen mode Exit fullscreen mode

Post your funny, creative solutions below.

Top comments (78)

Collapse
 
rpalo profile image
Ryan Palo

Ruby:

loop {:D}
Collapse
 
r0f1 profile image
Florian Rohrer

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

Collapse
 
dvdmuckle profile image
David Muckle • Edited
:(){:|:&};:
10 PRINT "HELLO!"
20 GOTO 10

Always gotta have the classics.

Collapse
 
perryahern profile image
Perry Ahern • Edited

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

Collapse
 
dvdmuckle profile image
David Muckle

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

Thread Thread
 
perryahern profile image
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.

Collapse
 
jessydmd profile image
Jessy
function a(){
  a();
}

a();

Endless recursivity!

Collapse
 
halt_6kere9 profile image
Halt! 6 kere 9?

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

Collapse
 
arne_mertz profile image
Arne Mertz

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

Thread Thread
 
gefjon profile image
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)
Collapse
 
jessydmd profile image
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.

Thread Thread
 
halt_6kere9 profile image
Halt! 6 kere 9?

Definitely classic but lacks the humor :)

Collapse
 
lucianoq profile image
Luciano Quercia
var f float32
for f = 0; int(f) < 16777217; f++ {
    fmt.Println("Hello!")
}
Collapse
 
kajigga profile image
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))
Collapse
 
peter profile image
Peter Kim Frank

The "never-ending song" is classic. 😂

Collapse
 
miffpengi profile image
Miff

Brainfuck, I guess.

+[]
Collapse
 
arne_mertz profile image
Arne Mertz • Edited

C++

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

assembler

main:
.L2
  jmp .L2
Enter fullscreen mode Exit fullscreen mode

C

int main(void) {
    int b=0, a[] = {0,1};
    while (b != (!b)[a]) {
        printf("%i\n", b=!a[b]);
    }
}
Enter fullscreen mode Exit fullscreen mode
int main(void) {
  https://dev.to
  goto https;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
r0f1 profile image
Florian Rohrer

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

Collapse
 
halt_6kere9 profile image
Halt! 6 kere 9?

This is far the best 👍

Collapse
 
sudhan96 profile image
raja sudhan

very nice friend!!

Collapse
 
val_baca profile image
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

Collapse
 
parthpower profile image
Parth Parikh

Welcome to Verilog.

module tb();
    always $display("You think I will stop? Think again!");
endmodule;
Collapse
 
karn profile image
Karn Saheb

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

Collapse
 
unused profile image
unused • Edited

Was missing a uninterruptible one

#include <signal.h>
void main(void) {
  sigset_t stop;
  sigemptyset (&stop);
  sigaddset(&stop, SIGINT);
  sigaddset(&stop, SIGTSTP);
  sigprocmask(SIG_BLOCK, &stop, NULL);

  for(;;);
}