0

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!

4
Contributors
6
Replies
8
Views
8 Years
Discussion Span
Last Post by majestic0110
0

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?

0

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

-1

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.

0

A server awaiting incoming connections may use an infinite loop, often in another thread.

0

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.