Internet
Fact-checked

At EasyTechJunkie, we're committed to delivering accurate, trustworthy information. Our expert-authored content is rigorously fact-checked and sourced from credible authorities. Discover how we uphold the highest standards in providing you with reliable knowledge.

Learn more...

What is an Infinite Loop?

M. McGee
M. McGee

An infinite loop is a condition that causes a computer program to continue executing a command without end. This is typically due to one of three causes: the program has no end condition, the program’s end condition is unattainable or a repeat command causes a program to continuously restart. Most of the time, an infinite loop will cause a computer to drastically slow down or even lock up. In early computers, these loops would often necessitate a restart, but modern operating systems will often catch them and terminate the program before they get out of hand.

Infinite loops exist within programming; other uses of the term are usually incorrect. In most cases, infinite loops are not the end goal of the program, and a problem exists somewhere in the code that causes the condition to occur. Each of the three main cases of an infinite loop is completely programming- and software-based.

Man holding computer
Man holding computer

When a program has no end condition, it will continue to execute its last set of instructions without end. In many cases, this will result in the program locking up as it waits for some final instruction that will never come. Other times, the last instruction given to the program was executing an instruction or processing a command. In these cases, it will continue to do these things without end. This will cause the computer to slowly fill with repeated commands from the infinite loop until the entire system is working on a problem with no end.

A similar situation exists when a program’s end condition is unattainable. In this case, the program can end, but it never will. The problem with the end point may be in the programming, or it may be a computer error that causes the condition. For example, if a program asks for a specific piece of information from a specific location, a programming error would be that the information is stored in a different spot. On the other hand, if the information is going to the program, but is interrupted due to interference from the user or another program, it may simply never arrive.

The last cause of an infinite loop is completely programming-based. Someplace within the programming is a command that tells the program to repeat something. While these commands are common, conditions should never allow the repeated command to come back to the initial repeat. If this happens, the program will execute a command, hit the repeat statement, then execute the command again, then repeat again, and so on. These loops are the most likely to be deliberately programmed, often as part of a piece of malware.

Discuss this Article

Post your comments
Login:
Forgot password?
Register:
    • Man holding computer
      Man holding computer