How would you determine a loop is a infinite loop and will break out of it.
Does anyone has the algorithm or can assist me on this one.
Thanks
There is no general case algorithm that can determine if a program is in an infinite loop or not for every turing complete language, this is basically the Halting Problem.
The idea of proving it is simple:
A
.B
that invokes A
on itself [on B
].A
answers "the program will halt" - do an infinite loopA
answers B
doesn't halt] - halt immidiatelyNow, assume you invoke A
on B
- the answer will be definetly wrong, thus A
doesn't exist.
Note: the above is NOT a formal proof, just a sketch of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With