0
What is base case in recursion. How does it works?
5 Antworten
+ 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 .
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.
0
so here, simple if serves as base case?
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.
0
oh! grt. thank u so much.