Talk:Infinite loop

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing (Rated Start-class)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
WikiProject Computer science (Rated Start-class, Mid-importance)
WikiProject icon This article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 Mid  This article has been rated as Mid-importance on the project's importance scale.

Infinite loops found in society??[edit]

Wtf is the deal with this section? This article is part of the computer science wikiproject. It is not social science. (talk) 08:11, 6 April 2008 (UTC)

I want to point out that I just checked the "citation" Rmarkosian gives in the "infinite loops in society" paragraph. It redirects to a website he made himself. It has absolutely ZERO to do with the topic of this article and I have removed it accordingly. That is ridiculous. (talk) 08:19, 6 April 2008 (UTC)

Perhaps this section is here because it a study of systems, and systems in and of themselves are not limited to CS. — Preceding unsigned comment added by (talk) 19:30, 8 July 2014 (UTC)

The example in BASIC[edit]

If a programmer were to create that 2-line example in QBASIC, QuickBASIC, or similar interpreter/compiler it would not be an infinite loop. The program would crash when it runs out of stack space. I changed it to:


This is a more correct example, as a DO LOOP instruction will not store a location in the stack for use by the RETURN function like a GOTO call does. —Preceding unsigned comment added by (talk) 01:05, 6 April 2008 (UTC)

I believe you are wrong. GOSUB stores a location on the stack (because it has to return again later) but GOTO does not; it's a simple jump. 2001:630:53:26:3035:D7FD:D5B0:4A05 (talk) 14:25, 3 December 2014 (UTC)

What a joke![edit]

The joke here (for the non-computer-programmer) is that infinite loop links to endless loop which links to infinite loop which links to endless loop which links to infinite loop which links to endless loop which links to infinite loop which links to endless loop which links to infinite loop which links to endless loop which links to infinite loop which links to endless loop which links to infinite loop which links to endless loop which links to infinite loop which links to endless loop which . . .

yes that's funny, but at the same time, not particularly helpful... sorry. Wesley
Can't there be any jokes in the Wikipedia? Sheesh! (I won't un-revert if someone de-humorizes them.) User:Ed Poor
There are Jokes in Wikipedia, as well as humour, laughs, fun and even Sheesh!

But surely they are not the same thing.

I suggest that:

  • An endless loop is any loop that connects back to its self with no way of getting out.
  • An infinite loop is a loop constructed of an infinite number of instructions and therefore only loops back after an infinite amount of time, or, more practically, never.

user:Perry Bebbington

I've never heard infinite loop used to mean this. I've always heard infinite loop used in the meaning above for endless loop: it is defined this way in the Jargon Lexicon at endless loop does not appear there. -- Olof

Thank you, Axel and Lee. It looks just about finished now. User:Ed Poor, unoffical "spirit of Larry"

Fair enough. user:Perry Bebbington

It seems fair game to link them to each other, it is not like the article was deleted to just include the other link! —Preceding unsigned comment added by Bennyj600 (talkcontribs) 21:54, 27 April 2009 (UTC)


I'm actually a little tiny bit surprised that there is no mention that this is technically a misnomer. For something to be infinite, it must be growing without bounds. I have yet to see a program loop that "grows" let alone increases the rate of growth. Additionally, these loops all terminate - if nothing else, the programmer will pull the plug on the machine; the loop will stop. --Connel MacKenzie 06:24, Apr 6, 2005 (UTC)

Kind of a bizarre over-interpretation of the words, so not surprising no one would mention it. Also, only possible to "pull the plug" on a physical machine; the concept applies to theoretical constructs such as Turing machines, no plug-pulling there. Stan 14:09, 6 Apr 2005 (UTC)
In a theoretically exact implementation, the time required to execute the loop is infinite Superm401 01:55, Apr 14, 2005 (UTC).
I agree with the misnomer notion. While you surely cannot pull the plug on a theoretical construct like a turing machine, it is still misleading to call the concept "infinite loop". At every point in time it will only have executed a finite number of iterations, and it will never enter its "infinite-th" iteration. That is the same misconception that leads some people to believe the integers actually contain an element "infinity". They grow without bound, their cardinality is infinite, but every single one of them is finite. There may be valid theoretical constructs that allow a loop to execute an infinite number of iterations (maybe related to Omega language), but that's probably not the concept written about in this article.
I also find it strange to talk about the time needed to "execute" an endless loop. Since they do not end by definition, even an infinite amount of time won't bring an endless loop to its end. In short, endless loops are not executable in the usual sense - they wouldn't cause programmers headaches if they were.
So, I'm voting for the term "endless loop" or at least a clarification of both terms, since "loop without end" is what they are, not "loop running/having run for an infinite time/nr. of iterations". If no one objects, I'm gonna add a clarification myself. Catskineater (talk) 03:45, 12 January 2010 (UTC)
Similarly you could say that it's not an endless loop — the loop ends when you pull the plug. I fail to see how "endless loop" is an improvement. The term "infinite loop" is ubiquitous in programming lingo, we should stick to that. -- intgr [talk] 22:32, 13 January 2010 (UTC)
I don't agree that this is a misnomer. No doubt you have a source that defines infinite as "growing" without bounds (I didn't find one), but even if you use that definition, the number of times the loop executes is the thing that grows without bounds, or the time taken to completion - both of which seem perfectly valid to me. I hardly think the user pulling the plug or any other externally acting force is relevant. Any number of computer science concepts would be wrong if you had to take power failure, someone attacking the RAM module with a soldering iron, bear attack, etc. into account. ("I've managed to rewrite your O(n^2) algorithm to be O(1)", "Really?", "Yes - the code's the same, but you drop the laptop into a volcano after the first iteration.", "Good thinking - that would definitely halt the program.") (talk) 11:27, 8 August 2014 (UTC)

Recursion unimportant?[edit]

Infinite recursion redirects to infinite loop. A combined discussion might be useful, but there isn't anything about recursion there at all. Similarly, stack overflow (the result of infinite recursion!) redirects to buffer overflow, which is unreleated (although buffers that overflow onto the stack could be called a stack overflow, that's not the only kind of stack overflow). Is there some reason that there's no discussion of the subject at any of the expected places? Is infinite recursion considered insufficiently notable when divorced from other problems? --Tardis 01:09, 4 May 2005 (UTC)

Infinite recursion rewrite[edit]

Technically, an infinite loop can only occur in iterative programming, which is programming that repeats itself until some condition is met. However, infinite recursion can occur in recursive programming, and an infinitely recursive sequence can be seen as a pseudo-infinite loop. Recursive functions operate by solving part of a problem, then calling on themselves to solve the rest. For example, a recursive function to sum the numbers up to a number n might add n to the sum of the numbers up to n-1. The way this process ends is with a special case. In this situation, for instance, if n were 1 the function would return 1. It is possible to create infinite recursion by failing to have that ending condition, meaning the function theoretically calls itself forever. (It would actually run out of stack space.) Recursion is perfectly safe with an adequate ending condition.

I rewrote this. The distinction given between infinite loop and infinite recursion above isn't exact (see "LAMBDA: The Ultimate GOTO" by Guy Steele). I used the same example (plus a more trivial one), but with code. --Mgreenbe 13:41, 23 January 2006 (UTC)

This should...[edit]

... null result. -- Chris 18:14, 5 November 2006 (UTC)

tight loop[edit]

Tight loop links to this article. Is it the same as infinite loop? --Abdull 08:02, 6 July 2007 (UTC)

No. A tight loop is a loop with few instructions in the body that's executed many times (they are prime candidates for optimization). Infinite loops are often tight, but a tight loop is rarely infinite. The term "tight loop" doesn't warrant a separate article; at best it's dictionary material. The redirect isn't really appropriate, though. 15:15, 30 September 2007 (UTC)

Request for addition[edit]

Is there any standard/provable practices for avoiding and/or detecting infinite loops in a system? Can a check be made to the effect of "is this instruction causing an infinite loop? Or is that perhaps, on the contrary, theoretically impossible due to the halting problem? If so, a link and a blurb about how this problem relates to infinite loops would be useful. —Preceding unsigned comment added by (talk) 12:56, 27 July 2008 (UTC) I see now that there is actually a very brief paragraph linking to the halting problem. I still think it would be nice if it was featured more prominently. —Preceding unsigned comment added by (talk) 13:02, 27 July 2008 (UTC)

Obviously "See also" should include a link to Infinite Loop[edit] has been done so many times because it is funny and encyclopedic. This page is surely an exception to the "no self-links" rule, which is overwritten by the democratic rule of Wikipedia (the number of people wanting to add the link is greater than the number of people wanting to remove it). Please tell us why this argument is invalid or I'll add the link. ··gracefool 10:21, 10 July 2009 (UTC)

Could not agree more. The somewhat snarky HTML comment in that section notwithstanding, it's exactly what that section needs. It's "been done, many times", because it's AWESOME. —Preceding unsigned comment added by (talk) 05:09, 7 May 2010 (UTC)

C++ Example[edit]

I added one that is a perfect infinite loop, correct? —Preceding unsigned comment added by Segiddins (talkcontribs) 00:55, 19 July 2009 (UTC)

while ( true )[edit]

Is it considered bad form to use while ( true )? E.g.,

while ( true ) {
    if ( $foo->bar () ){

This is a simplistic example since here one could just as easily use

while ( !$foo->bar () ) {}

However, I'm sure we have all run into situations in which it was tempting to use a while ( true ), but is it bad form? Tisane talk/stalk 15:33, 16 June 2010 (UTC)

the rule is that every loop terminates, and when you pretend it doesn't like that, it makes the code harder to read. The example you gave is trivial, and all programming readability conventions can be ignored for trivial cases.
int main()
       /* do your main program loop in all its complexity*/
       /*Do even more*/
You can see how someone coming by later would have a hard time knowing what was going on. The condiiton at the top of the loop helps because it provides immediate context. i kan reed (talk) 16:59, 7 June 2011 (UTC)
There are some scenarios where while(true) is useful. In such cases I find it is generally useful to add a comment noting where I expect the loop to terminate, eg:
int main()
   while(1) // ... until break when exitCodeReceived
       /* do your main program loop in all its complexity*/
       /*Do even more*/
Mitch Ames (talk) 10:39, 9 June 2011 (UTC)

Image should be removed[edit]

The image has nothing to do with the subject matter of the article, leading to confusion. There is an article on the street, this image does not belong here. —Preceding unsigned comment added by (talk) 16:57, 14 July 2010 (UTC)

Merger proposal[edit]

Alderson loop is a short article should be merged here. The loop is nothing special, it's just a common type of infinite loops and there is no reason to keep it as a separate article. Zakhalesh (talk) 17:40, 19 February 2011 (UTC)

No opposing opinions, so I'll get on with the merge. Zakhalesh (talk) 10:33, 26 February 2011 (UTC)

Done. Improve the section if you wish! Zakhalesh (talk) 10:56, 26 February 2011 (UTC)


This should be redirected to Infinite loop. Ten Pound Hammer, his otters and a clue-bat • (Otters want attention) 01:58, 15 April 2011 (UTC)


A humorous example of an infinite loop in Java:

for ( ; ; )
System.out.println("Alice: When are you going to stop looping?");
System.out.println("Bob: Just one more time!");

Maybe we could include it, but IDK what section. Thanks! (talk) 21:46, 3 February 2012 (UTC)

Undefined Behaviour[edit]

The C example in section 1.2.1 has undefined behaviour, as the int variables will eventually overflow; on a typical non-optimizing compiler the loop will terminate. TimothyEBaldwin (talk) 18:06, 10 February 2012 (UTC)

Pseudo-infinite loops??[edit]

...are just very long loops? This is so scientific. Long in code? Long in execution? Does someone call a long loop pseudo-infinite? -- (talk) 19:04, 11 April 2012 (UTC)

"Alderson Loop" example is incorrect[edit]

The example of an "Alderson loop," near the end of the article, is not an endless loop at all. It's fairly simple to see that if (as the comments) say, the first section of the 'if' block never executes, then the 'else' block (and therefore the 'break' statement) always executes. Am I misunderstanding the intention of the section, or is that code just plain wrong?

If I'm not misunderstanding, the author's intention was this:

while (true) {
    printf("Input a number to add to the sum or 0 to quit");
    i = getUserInput();
    if (!(i * 0)) {     // if i times 0 is false, add i to the sum
        sum += i;       // always executes; the condition should read (!(i == 0))
    } else {
        break;          // terminate the loop; exit condition exists but is never reached

Alex Heinz (talk) 16:54, 5 September 2012 (UTC)

 Fixed. You're right that it was broken; thanks! I didn't use your exact logic, but tried to make something that was less involved with the if-else path. —chaos5023 (talk) 17:20, 5 September 2012 (UTC)

Undecidable problem[edit]

This sentence clearly refers specificly to Undecidable problem that is a subcategory of the decision problem and not to decision problems in general, it was laborous to find information about undecibility from that article. Also "Undecidable problem" article refers to "Decision problem" at the very begining so that if the reader does not understand the term he or she can check that out easily. (talk) 10:27, 22 October 2013 (UTC)

Very Hard HSCTF Problem[edit]

HSCTF Participants should also be made aware that they should reverse the order of the first part and remove every other letter starting with removing the second to get their key. — Preceding unsigned comment added by Temptemptemp42 (talkcontribs) 01:59, 20 May 2014 (UTC)

Another BASH Example[edit]

I'm not sure if we should bother including it, as it is less useful, but I recently learned the following:

yes This loop is a trap!


This loop is a trap!

This loop is a trap!

This loop is a trap!

...and so on. NickNackGus (talk) 02:25, 8 October 2014 (UTC)

That's not a loop per se; there is probably a loop inside the source code of the yes utility, though.--greenrd (talk) 09:21, 7 December 2014 (UTC)