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 (84)

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 on
:(){:|:&};:
10 PRINT "HELLO!"
20 GOTO 10

Always gotta have the classics.

Collapse
 
perryahern profile image
Perry Ahern • Edited on

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

Brainfuck, I guess.

+[]
Collapse
 
arne_mertz profile image
Arne Mertz • Edited on

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
 
sudhan96 profile image
raja sudhan

very nice friend!!

Collapse
 
halt_6kere9 profile image
Halt! 6 kere 9?

This is far the best πŸ‘

Collapse
 
val_baca profile image
Valentin Baca • Edited on

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 on

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(;;);
}
Collapse
 
patriklarsson profile image
Patrik

Only to make people hate me...

HTML

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

Collapse
 
eminemence profile image
eminemence • Edited on

Shell command :
yes

Collapse
 
_rodrigooliv profile image
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")
Collapse
 
andreasjakof profile image
Andreas Jakof

C#

class Program
{
   public static IEnumerable<string> HelloWorld()
   {
      while(true) yield return β€žHello Worldβ€œ;
   }
   public static void Main(string[] args)
   {
      foreach (string  s in HelloWorld())
      {
         Console.WriteLine(s);
         Thread.Sleep(1000);
      }
   }
}
Collapse
 
kuziandus profile image
Dan Suzuki

Scala

@tailrec 
final def diamond(b: Boolean): Boolean = 
   if(b) diamond(b) 
   else b

Hey 😍

Want to help the DEV Community feel more like a community?

Head over to the Welcome Thread and greet some new community members!

It only takes a minute of your time, and goes a long way!