Reputation: 461
During writing program I often come across infinite loop.
How can I write a program which takes another program as input and determine whether there is any infinite loop or not?
Upvotes: 3
Views: 4875
Reputation: 59035
You can't. And by that, I don't mean "it's really hard". I mean "this is a well-known problem in computer science that people have been trying to solve since the inception of the field, and if you could solve it you would immediately be world-famous."
Alan Turing proved that it cannot be solved, and no one has been able to disprove it, which is why I say "if you could solve this problem, you would be world famous."
See The Halting Problem.
Upvotes: 5