# Fake infinite loop [closed]

The challenge is to write a fake infinite loop in any imperative programming language.

At first sight, the code should seem not to halt at all.

As a naive example:

int f(int x)
{
return f(4.0);
}

int f(double x)
{
return 0;
}


But remember
You're not allowed to use overflows:

int f(int x)
{
if(x < 0) return -1;
return f(x*x);
}


is illegal. When the number exceeds the integer limit, the function will stop. It's a good trick. But not good enough :)

• For the record, I voted to close as duplicate rather than as unclear, so I don't see any point in trying to improve the clarity, but since I see that someone has voted to reopen: the second example is still unclear IMO. What if I call f(0)? (And the first example still wouldn't fool anyone with an IQ above 90 and at least two hours of programming experience). Jul 8, 2014 at 8:23
trap 'exec "$0"' exit  It re-execs itself when it should exit. So it will never really exit. It doesn't have the shebang. So you must run it like bash a.sh. And $0 will probably not be something executable.