Recursive Loop

Why Trust Techopedia

What Does Recursive Loop Mean?

A recursive loop is said to have occurred when a function, module or an entity keeps making calls to itself repeatedly, thus forming an almost never-ending loop. Recursive constructs are used in several algorithms like the algorithm used for solving the Tower of Hanoi problem. Most programming languages implement recursion by allowing a function to call itself.

Advertisements

Recursive loops are also known simply as recursion.

Techopedia Explains Recursive Loop

A recursive loop is a special type of looping construct where a particular entity tries to invoke itself from within its loop code. Thus the entity keeps calling itself until a specific condition or break is specified. Recursive loops are usually implemented with the help of a recursive function call where a call to a particular function is placed within the function definition itself.

The programming languages capable of implementing recursive loops can solve the problems that require the use of iterative structures like "while" and "for" just by using recursive loops alone. Thus recursive loops can replace the traditional loop constructs and are sometimes useful in creating less bulky code. It also simplifies the code and helps in breaking down complex codes into simple statements.

Some of the most common problem applications of recursive functions include the Tower of Hanoi, computation for series for e = 1/0! +1/1!+1/2+…, computation of gcd, factorial and so on.

Recursion is also used in cases when the programmer is not sure about the exact size of data.

Recursion in computing can be classified into the following types:

  • Single recursion
  • Multiple recursion
  • Indirect recursion
  • Anonymous recursion
  • Structural recursion
  • Generative recursion

Using recursive loops may affect the performance of the program. Recursive loops make use of memory stacks and when the stacks are full, the loop may terminate before the intended termination time.

Advertisements

Related Terms

Margaret Rouse
Technology Expert
Margaret Rouse
Technology Expert

Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.