We all know that detecting infinite loops is impossible in general, but in practice, if a while loop is running too long, you can just stop it. Every while loop should have an implicit counter that keeps track of how many times it runs. In an interactive application or game, the virtual machine can kill the loop if it goes longer than one cycle of the event loop. We do this in unitymal (although there are no while loops, because it’s Lisp). Every function call, every closure, has just such a counter. If it gets too high, we throw an exception so there is no infinite regress. You can’t have a user’s bad code bring down the entire virtual world.