Detecting an infinite loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Detecting an infinite loop?

Is there any way to detect an infinite loop in a function without resorting to monitoring the internal state of variables within the function?

24th Nov 2018, 10:06 PM
Jonathan Shiell
3 Answers
+ 5
Isn't this the Halting problem? https://en.m.wikipedia.org/wiki/Halting_problem It is said to be an undecidable problem. :>
25th Nov 2018, 1:01 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
You can also - primitive but works - put a random print statement in there and look what happens.
24th Nov 2018, 10:33 PM
HonFu
HonFu - avatar
0
You can set a timeout. then check and break the loop after specified duration.
24th Nov 2018, 10:27 PM
Sokrat_Poghosyan
Sokrat_Poghosyan - avatar