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.

Oldest comments (78)

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
 
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
 
r0f1 profile image
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");
}
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
 
miffpengi profile image
Miff

Brainfuck, I guess.

+[]
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
 
iglosiggio profile image
Ignacio Losiggio • Edited

A classical example :P

(λx.x x)(λx.x x)

Or in ES2015

(a=>a(a))(a=>a(a))
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
 
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
 
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
 
danielescoz profile image
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).

(It might eat your RAM)

Collapse
 
michie1 profile image
michie1
while(1){}
Collapse
 
simpgeek profile image
Nigel Kirby

2 JS classics

let a = 1
while(a !== '1')
    console.log('sup')
let a = 0.1 * 0.2
while(a !== .02)
    console.log('sup')
Collapse
 
ramriot profile image
Gary Marriott • Edited

Erlang:

loop() ->
do:someVitalTask(),
loop().

Collapse
 
eminemence profile image
eminemence • Edited

Shell command :
yes

Collapse
 
nektro profile image
Meghan (she/her)

Javascript

setInterval(function() {}, 1);
Collapse
 
terceranexus6 profile image
Paula

This post is so dangerous oh my god