Content deleted Content added
Jerryobject (talk | contribs) Small WP:COPYEDITs WP:EoS: WP:TERSE, clarify. WP:LINKs: needless: underscores > spaces, WP:PIPE > WP:NOPIPE. Cut needless whitespace characters (carriage returns, spaces) in sections: to standardize, aid work via small screens. MOS:FIRSTABBReviation clarify, define before WP:ABBR in parentheses. WP:CATEGORYs add. |
|||
Line 1:
{{
{{About-distinguish|the programming term|Infinite Loop (street)|Infinite Loop (book)}}
{{Redirect-distinguish|Endless loop|Endless Loop (album)}}
{{Loop constructs}}<!--
In [[computer programming]], an '''infinite loop''' (or '''endless loop''')<ref>{{cite web
==Overview==
This differs from "a type of computer program that runs the same instructions continuously until it is either stopped or interrupted".<ref>{{cite news
<syntaxhighlight lang="lua">
how_many = 0
Line 56 ⟶ 55:
==Details==
An ''infinite loop'' is a sequence of instructions in a [[computer program]] which loops endlessly, either due to the [[control flow#Loops|loop]] having no terminating condition,<ref>{{cite magazine
|author=<!-- Unstated -->
|archive-date=July 26, 2019
==Intended vs unintended looping==
Line 82:
Modern interactive computers require that the computer constantly be monitoring for user input or device activity, so at some fundamental level there is an infinite processing [[idle loop]] that must continue until the device is turned off or reset. In the [[Apollo Guidance Computer]], for example, this outer loop was contained in the Exec program,<ref>{{cite web
Modern computers also typically do not halt the processor or motherboard circuit-driving clocks when they crash. Instead they fall back to an error condition displaying messages to the operator (such as the [[blue screen of death]]), and enter an infinite loop waiting for the user to either respond to a prompt to continue, or reset the device.
Line 104:
[[File:Infinite loop BSOD.jpg|thumb|A [[blue screen of death]] on [[Windows XP]]. "The [[device driver]] got stuck in an infinite loop."]]
Most often, the term is used for those situations when this is not the intended result; that is, when this is a [[software bug|bug]].<ref>{{cite web
One common cause, for example, is that
While most infinite loops can be found by close inspection of the code, there is no general method to determine whether a given program will ever halt or will run forever; this is the [[undecidable problem|undecidability]] of the [[halting problem]].<ref>{{cite web|url=https://www.geeksforgeeks.org/halting-problem-in-theory-of-computation|title=Halting Problem in Theory of Computation|date=3 October 2018|access-date=22 January 2020|archive-date=9 August 2020|archive-url=https://web.archive.org/web/20200809100104/https://www.geeksforgeeks.org/halting-problem-in-theory-of-computation/|url-status=live}}</ref>
Line 120:
==Interruption==
As long as the system is responsive, infinite loops can often be interrupted by sending a signal to the process (such as [[SIGINT (POSIX)|SIGINT]] in Unix), or an [[interrupt]] to the processor, causing the current process to be aborted. This can be done in a [[task manager]], in a terminal with the [[Control-C]] command,<ref>{{cite web
==Language support==
Line 202:
This creates a situation where <code>x</code> will never be greater than 5, since at the start of the loop code, <code>x</code> is assigned the value of 1 (regardless of any previous value) before it is changed to <code>x</code> + 1. Thus the loop will always result in <code>x</code> = 2 and will never break. This could be fixed by moving the <code>x = 1</code> instruction outside the loop so that its initial value is set only once.
In some languages, programmer confusion about
<syntaxhighlight lang=c>
#include <stdio.h>
Line 219:
</syntaxhighlight>
The expected output is the numbers 0 through 9, with an interjected "a equals 5!" between 5 and 6. However, in the line "<code>if (a = 5)</code>" above,
===Rounding errors===
{| style="float:right; border: 1px solid grey;"
|-
Line 307 ⟶ 306:
Infinite recursion is a special case of an infinite loop that is caused by [[recursion (computer science)|recursion]].
The following example in [[Visual Basic for Applications
<syntaxhighlight lang="vbscript">
Sub Test1()
Line 326 ⟶ 325:
===Alderson loop===
''Alderson loop'' is a rare slang or [[The Jargon File|jargon]] term for an infinite loop where there is an exit condition available, but inaccessible in
A C-like pseudocode example of an Alderson loop, where the program is supposed to sum numbers given by the user until zero is given, but where the
<syntaxhighlight lang="C">
int sum = 0;
Line 345 ⟶ 344:
The term allegedly received its name from a programmer (last name Alderson) who in 1996<ref>{{cite web
==See also==
Line 363 ⟶ 362:
==References==
{{Reflist}}
==External links==
Line 369 ⟶ 368:
{{DEFAULTSORT:Infinite Loop}}
[[Category:Control flow]]
[[Category:Iteration in programming]]
[[Category:Programming language comparisons]]
[[Category:Recursion]]
[[Category:Software bugs]]
[[Category:Articles with example BASIC code]]
[[Category:Articles with example C code]]
[[Category:Articles with example Java code]]
[[Category:Articles with example PHP code]]
[[Category:Articles with example Python (programming language) code]]
[[Category:Articles with example Rust code]]
|