Infinite loop

Infinite loops in computer science are loops that are executed again after each execution, if the execution is not aborted by external influences. External influences are those that are not included in the regular course of the program, such as turning off the computer.

Programming

Infinite loops can arise with programming error if the termination condition is not defined or can not occur. However, for example, to query the mouse a desired loop that waits for a motion, and during movement triggers a reaction, this behavior is known as polling. In multitasking systems usually several infinite loops run ( " event loops " ) to collect user input from parallel, in a single-tasking system usually runs only one simultaneously.

Incorrect termination conditions often cause unintended infinite loops. Depending on the program, such an error can be expressed in different ways. If within the loop repeats fuselage resources - such as main memory - are occupied and not released again, this generally results in a memory leak. But infinite loops can express to the user ( "freezing" ) is also characterized by simple inactivity of the program.

Strictly speaking, to distinguish whether a loop has no termination criterion if it is never fulfilled, or whether this is the case only for certain input parameters. The first case is selected either deliberately or can be easily found by debugging the program. The second situation is conceptually similar to the last case is almost always undesirable and can be very difficult to find, since it may rarely occur. It occurs, for example, when the state of the program at the beginning of the loop does not meet the loop invariant.

Examples

  • An iteration that reaches no termination condition,

/ / Programming language: Delphi (Object Pascal )     i: = 0;       while i < 10 do       begin       / / ...       / / The termination condition is not reached, there does not change the value of the variable i,       / / If the programmer as an instruction i: = i 1 has forgotten at the end of the loop       end; or

Float f = 0.1        while ( f! = 1.0)          ...          f = 0.1 / / Since 0.1 is binary periodic, 1.0 is never reached exactly        end recursion, which does not reach a termination condition. In this case, the program crashes mostly off due to a stack overflow after some time.

( define ( faculty- N)        ; you forget the base case (< = N 1) or similar to examine         (* N ( faculty ( - N 1 )))       ) the simplest case, an infinite loop is executed as long as is 'true' true - so forever. ( Unless there are inside the loop one or more break statements, then it is not a " real" infinite loop. )

While (true)       {         ...       } there was no defined termination condition, so the loop will always be executed

Loop         ...       end loop countermeasures

To prevent accidental infinite loops in programs, the loop condition can be formally verified ( eg with the wp- calculus ). However, this is a very expensive process and generally even an unsolvable problem (see halting problem ), even for small programs.

Another method, the unintended infinite loops though can not prevent, but temporary, is a so-called Watchdog: If a program stops regularly signaled that it is running properly, it can react accordingly ( eg notify the user or the terminate the program).

Other examples

Simple batch programs with malicious function the loop to bring the computer through a high resource utilization to crash. Here, the batch files in a new process itself to new. This process is repeated indefinitely, so that the newly launched processes and the kernel handling the same the other applications and processes slow down. Unresponsive to enter, so this is like a system crash and the computer must be restarted by a reset.

Also, geometric figures are possible infinite loops, such as the circle or the Möbius band.

Acoustic feedback is an infinite loop, because always the same sound pattern only output from the speakers, recorded by the microphone again, and is output as recurring.

In glossaries or dictionaries is sometimes an infinite loop recursively - using the practical example of itself - explains:

In the German language, this term is infinite loop sometimes used to describe a process in which " the cat's tail biting ", for example:

  • You end up with a hotline after selecting all that apply back at the starting point (see also Buchbinder Wanninger of Karl Valentin).
  • A discussion " round in circles ", and appears without additional new arguments in the foreseeable future to lead to any result.
  • In a "vicious circle" is the result of a problem at the same time its cause, whereby a solution of the problem is impossible.
308058
de