We are independent & ad-supported. We may earn a commission for purchases made through our links.
Advertiser Disclosure
Our website is an independent, advertising-supported platform. We provide our content free of charge to our readers, and to keep it that way, we rely on revenue generated through advertisements and affiliate partnerships. This means that when you click on certain links on our site and make a purchase, we may earn a commission. Learn more.
How We Make Money
We sustain our operations through affiliate commissions and advertising. If you click on an affiliate link and make a purchase, we may receive a commission from the merchant at no additional cost to you. We also display advertisements on our website, which help generate revenue to support our work and keep our content free for readers. Our editorial team operates independently of our advertising and affiliate partnerships to ensure that our content remains unbiased and focused on providing you with the best information and recommendations based on thorough research and honest evaluations. To remain transparent, we’ve provided a list of our current affiliate partners here.
Software

Our Promise to you

Founded in 2002, our company has been a trusted resource for readers seeking informative and engaging content. Our dedication to quality remains unwavering—and will never change. We follow a strict editorial policy, ensuring that our content is authored by highly qualified professionals and edited by subject matter experts. This guarantees that everything we publish is objective, accurate, and trustworthy.

Over the years, we've refined our approach to cover a wide range of topics, providing readers with reliable and practical advice to enhance their knowledge and skills. That's why millions of readers turn to us each year. Join us in celebrating the joy of learning, guided by standards you can trust.

What Is a Recursive Call?

By Franklin Jeffrey
Updated: May 16, 2024
Views: 6,825
References
Share

In programming, a recursive call is a command within a subroutine or function that tells the program to run the same subroutine again. The repeat performance may be the direct result of the function, or a second function may be triggered that, in turn, refers back to the first function. A recursive call has some similarities to the dreaded infinite loop, but the subroutine always has a conditional statement that tells the program when to stop repeating the recursion.

The concept of recursion is perhaps best illustrated through the use of an example. Suppose a roofer is applying new shingles to a home. To begin, he must carry a bundle of shingles to the roof. Once he has nailed the first bundle in place, he must climb down the ladder, retrieve another bundle and nail it in place. The process continues as a series of "go, fetch, return" until the last shingle has been applied. At that point, the roofer is free to move on to the next job or go home.

Although the example is an oversimplification, it contains all of the elements of a recursive call. There is a starting point, the roofer must retrieve what he needs, return to the beginning and, when the final condition is met, stop. This is basically what the program does; it starts, implements an action, returns to itself and terminates when the ending condition occurs.

The ending condition is referred to as the base case. It is essential for all recursive calls; without it, the function would continue to repeat. At best, this results in draining the system's memory resources. Normally the overload will crash the program at some point, but by the time the problem is discovered, significant damage may be done.

Experienced programmers might recognize the similarity between a recursive call and a "for" or "while" loop. If, for example, the goal is to find the total inventory count of all stock with part numbers greater than 999, a "for" loop tells the program to locate all qualifying instances and a "while" loop tells the program to execute the loop only while the stated condition is valid. A recursive call might be said to combine some of the features of these loops with an "if-then-else" statement; if this condition is true, then do this, or else do something different if the condition is false. Recursion typically allows for more compact code, however, and allows the problem to be passed to the function nearer the point it is needed.

Share
EasyTechJunkie is dedicated to providing accurate and trustworthy information. We carefully select reputable sources and employ a rigorous fact-checking process to maintain the highest standards. To learn more about our commitment to accuracy, read our editorial process.
Link to Sources
Discussion Comments
Share
https://www.easytechjunkie.com/what-is-a-recursive-call.htm
Copy this link
EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.

EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.