Hi all, just a quick question....
is there ever a need to implement an infinite loop? in what situations would it be a good idea to use one (if any)? thanks for your time!

10 Years
Discussion Span
Last Post by majestic0110

could an infinite loop be used to check if certain events (eg login) have occurred? along with break statements to break out of the loop?


break statement inside the loop doesn't make it an infinite loop. (that's my opinion of course) Others might have better suggestions


While not really being "infinite", while(true) { } loops are seen fairly often in concurrent processes for things like polling for tasks in a work queue. They execute in a try-catch block for InterruptedException and that provides the mechanism for shutting them down gracefully.


ok Ezzaral and Phaelax thanks for the replies that does make sense. I am just aware that often infinite loops are a product of logic errors and wondered if there was ever a need to use an infinite loop. Cheers!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.