Though I know it'll be a bit silly to ask, still I want to inquire more about the technical perspective of it.
A simple example of an infinite loop:
public class LoopInfinite { public static void main(String[] args) { for (;;) { System.out.println("Stack Overflow"); } } }
How can I interrupt (stop) this infinite loop from outside of this class (e.g., with the help of inheritance)?
You can press Ctrl + C .
An infinite loop will run indefinitely, until it is explicitly broken out of using either a break , exit or raise statement.
I feel dirty even writing this, but...
From a different thread, you could call System.setOut()
with a PrintStream
implementation, which throws a RuntimeException
when you call println()
.
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