Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are all infinite loops bad?

Out of curiousity, are all infinite loops bad?

  • What are the bad effects and consequences that will happen if you run an infinite loop?
  • Also, if they are not all bad, could you please give some examples when they will serve a meaningful purpose?
  • And do they need to have something to close the instance? For example, we always close the StreamReader after using it in Java (not sure why).
like image 583
Theone Avatar asked Jun 29 '12 06:06

Theone


1 Answers

I'm not sure what you mean by "bad".

Infinite loops are common in many scenarios mostly event handler loops where the program sits in an infinite loop and waits for some external event to occur which is handles and goes back to wait. This is the way GUIs and many servers are programmed.

Update They're sufficiently useful to justify a construct just for infinite loops in some languages.

like image 161
Noufal Ibrahim Avatar answered Sep 21 '22 13:09

Noufal Ibrahim