Infinite loop

From Academic Kids

An infinite loop is a sequence of instructions in a computer program which loops endlessly. The Infinite Loop is also a street in California, see below.

Contents

Looping

Looping is repeating an instruction set until a specific condition is met. An infinite loop occurs when the condition will never be met, due to some inherent characteristic of the loop. There are a few situations when this is desired behavior. For example, many server programs such as Internet or database servers loop forever waiting for and servicing requests. More often, though, the term is used for those situations when this is not the intended result; that is, when this is a bug. Such errors are made by experienced programmers as well as novices, and their causes can be quite subtle.

One common cause, for example, is that the programmer intends to iterate over a collection of items such as a linked list, executing the loop code once for each item, but improperly formed links which create a reference loop in the list, causing the code to continue forever.

Unexpected behavior of a terminating condition can also cause this problem. Here is an example (in C):

 float x = 0.1;
 while (x != 1.1) {
   x = x + 0.1;
   printf("x = %f\n", x);
 }

On some systems, this loop will run ten times as expected; but on some systems it will never terminate. The problem is that the loop terminating condition (x != 1.1) tests for exact equality of two floating point values, and the way floating point values are represented in many computers will make this test fail, because 1.1 cannot be represented exactly. The best way to fix this would be to use an integer as the loop index. A loop index is a variable that stores the point at which the computer is at in the loop. This is necessary so the computer can know when to leave the loop. In addition to using integer array indices, it is best to avoid using != as a loop condition as well. Instead one should use <, <=, >, or >= in most situations.

A similar problem occurs frequently in numerical analysis: in order to compute a certain result, an iteration is intended to be carried out until the error is smaller than a chosen tolerance. However, because of rounding errors during the iteration, the tolerance can never be reached, resulting in an infinite loop.

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 undecidability of the halting problem.

Pseudo-infinite loops

A pseudo-infinite loop is a loop that appears infinite but is really just a very long loop.

Impossible Termination Condition

An example in C:

unsigned int i;
for (i = 1; i > 0; i++)
{ loop code }

It appears that this will go on forever, but in fact the value of i will eventually reach the maximum value storable in an unsigned int; after this, adding 1 to it will yield 0, breaking the loop. The actual limit of i depends on the details of the system and compiler used. In an "ideal" implementation, this would be an infinite loop.


Infinite Recursion

Technically, an infinite loop can only occur in iterative programming, which is programming that repeats itself until some condition is true. 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.



Infinite Loop is a street encircling the buildings of Apple Computer's headquarters in Cupertino, California. Each building has a number which is also its single-digit address on the Loop, and so Apple's official mailing address is "1 Infinite Loop". The loop connects to Mariani Avenue, which was the former street address of Apple HQ; early printed material contains the address "20525 Mariani Avenue".

The name was inspired by the concept of the infinite loop, as above. When Apple purchased a Cray-3 in the early 1990s, there was a saying: "The Cray-3 is so fast it can execute an infinite loop in under 2 seconds!"

See also

External links

Template:Mapit-US-streetscalede:Endlosschleife ru:Бесконечный цикл

Navigation

Academic Kids Menu

  • Art and Cultures
    • Art (http://www.academickids.com/encyclopedia/index.php/Art)
    • Architecture (http://www.academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (http://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (http://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools