Compilers can help prevent long-running loops by compiling the code for a loop differently.
At its most basic, a loop is a start-label and an end-label.
loop
x := 1
end loop
Currently, loops are compiled as:
START:
MOV [X],1
GOTO START
END:
Loops could be compiled as
START:
MOV [X],1
CALL YIELD
GOTO START
END: