What is Infinite Loop in Programming?

·

3 min read

Cover Image for What is Infinite Loop in Programming?

The reason behind the occurrence of an Infinite loop

Generally, there are six reasons that become the reason behind the occurrence of an infinite loop.

  1. No terminating condition

  2. Having one condition that can never be met

  3. Having a condition that causes the loop to start again and again

  4. Miss the incrementer or decrementer (if your logic needs one)

  5. continue statement in the wrong place (if your logic needs one)

  6. wrong comparisons in loop condition (less than or greater mixed up)

So whenever you get an infinite loop just check from these six conditions, there are high chances that you’ll get your mistake.

The harm that Infinite Loop can do

Mainly Infinite loop can harm your system in two ways:

  • **By using your processor time and power—**As a general rule if your processor is working on any process it takes time and power to do it. Same as any other process Once started infinite loop will use your processor's time and power. And at one point in time, it slows down your system and made it unresponsive.

  • By using your memory — In a computer mainly all running processes reside inside the RAM. And when an infinite loop occurs, it just started to fill up your RAM space and at one point in time your system will run out of memory and it can result in complete system failure.

Yes, that’s also true that modern operating systems like Windows 10, Linux, and macOS have a pre-defined mechanism to handle this kind of process. After reaching a certain level these operating systems can automatically kill these kinds of processes to avoid complete system failure. But again if implemented in a proper way an infinite loop can damage a lot.

How to Stop Infinite Loop

If you’re a developer and you have an infinite loop in the terminal application then (ctrl+c) will usually stop it. If it is a graphical application then you can kill the process via Task Manager or if you are using IDE then find the stop button. In most cases, this will terminate your infinite loop.

So, guys, that’s it for an infinite loop. Don’t be afraid if you have one. Every programmer meets with an infinite loop once in a lifetime. Just drink a cup of coffee, keep your mind cool, and check from above six conditions you’ll definitely find the solution.

Feel free to let me know if I miss something, I’ll love to learn it from you. Till then Keep Loving, Keep Coding. I’ll surely catch you up in the next article.

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitant that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

Jai Hind, Vande Mataram 🇮🇳

Follow me for more such content