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.

Latest comments (78)

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
 
kurtgokhan profile image
Gökhan Kurt
_=        '._.'   // Dude WTF

for       (;_;)   // Stop that pls

          _=_=_   // IDC LOL
Collapse
 
errietta profile image
Erry Kostala
#!/usr/bin/env perl

$SIG{INT} = 'IGNORE';

while ( 1 ) {
  print "stop me if you can\n";
  sleep 1;
}

# Pretty standard but I went a bit further and made it ignore CTRL-C as well, so you have to `kill -9` it :)
Collapse
 
val_baca profile image
Valentin Baca • Edited

The original post was tagged with javascript and dev.to has a bias toward javascript which is why it was tagged with that.

What language would you have picked? Because most languages do not have empty statements evaluate to true, so the block would have had to be for(;1;); which is not as neat IMO

Thread Thread
 
danielkun profile image
Daniel Albuschat

C

Collapse
 
nullpo profile image
Pablo

`T

2 bytes. Language: MATL

Collapse
 
benaryorg profile image
#benaryorg • Edited

Using C and TCO:


#define foo(x) _foo((x),1,0)

int _foo(int to,int cur,int acc)
{
  if((cur = 0) || (to = cur))
  {
    return acc;
  }
  return _foo(to,cur+1,acc+cur);
}

int main(void)
{
  return foo(10);
}
Collapse
 
lexplt profile image
Lex Plt • Edited

C++

#include <iostream>
int main(int argc, char* argv)
{
    std::cout << "argc is " << argc << std::endl;
    std::cout << main(argc, argv);
    return main(1, {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\0'});
}

C++ (even though the syntax highlithing is set to python)

#include <my_awesome_events_manager_lib>
using namespace my_awesome_events_manager_lib;
int main(void)
{
    auto playing = true;
    while (playing)
    {
        // handle events /!\
        if (getEvent()->type == QUIT) playing = !playing;
    }
    return 0x0;
}
Collapse
 
eugeniu_rtj profile image
Eugeniu T. • Edited

Elixir:

def infinite do
    infinite
end
Collapse
 
hryggrbyr profile image
Thomas Rigby
while (true) {
  console.log(!true)
}
Collapse
 
crhodes2 profile image
crhodes

Infinite insult in C

int YourIQ = 0;
while (YourIQ < 1)
{
    printf("You're stupid! ");

}