What is base case in recursion. How does it works? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is base case in recursion. How does it works?

12th Sep 2017, 9:01 AM
Bhawna sharma
Bhawna sharma - avatar
5 Answers
+ 2
instead of using the main function in a while loop . you can just make the function call itself again and again untill the condition is true .
12th Sep 2017, 9:49 AM
zakaria kasmi
zakaria kasmi - avatar
0
Without a base case the recursive method would call itself infinitly, making it an infinite loop. The base case is an exit condition you specify for the method that tells the program when to stop the loop, for example a simple if-statement.
12th Sep 2017, 2:21 PM
Shadow
Shadow - avatar
0
so here, simple if serves as base case?
13th Sep 2017, 3:06 PM
Bhawna sharma
Bhawna sharma - avatar
0
Yes, with an if-statement you can specify a condition when to exit the recursion. Every time the function calls itself it will check if the condition is true and eventually end the function. Additionally, you can have more than one base case.
13th Sep 2017, 5:22 PM
Shadow
Shadow - avatar
0
oh! grt. thank u so much.
17th Sep 2017, 4:07 PM
Bhawna sharma
Bhawna sharma - avatar