- Home/
- CDS & Defence/
- Article
Which keyword can be used for coming out of recursion? (a) break (b) return (c) exit (d) both break and return
By BYJU'S Exam Prep
Updated on: September 25th, 2023
The return keyword can be used for coming out of recursion. The return keyword is used to halt the execution of a function and return control to the calling function. When the break declaration was encountered, the program loop was immediately ended. The while or do from the switch or loop statements are immediately terminated when the break keyword is used.
Table of content
What is a return keyword?
The return keyword in Java causes a method to return a value. When the keyword is detected, the method will immediately return the value. This indicates that the method will end after the return keyword and that any local variables it has established will be deleted.
The return keyword can be used by programmers with or without a value. A value will be returned to the caller if one is provided. A null value will be returned in all other cases. When utilising the return keyword, there are a few recommended practices to follow. Let’s examine how this keyword operates in functions and the kinds of data it might return.
How to use return?
Return statements redirect the program outside of the execution of that block, similar to how a break statement does in a for-a-loop. In other words, a return statement hands back control to the caller immediately after exiting the current method. This functions similarly to how a break statement returns control to the preceding code block after promptly ending for a loop.
Summary:
Which keyword can be used for coming out of recursion?(a) break(b) return(c) exit(d) both break and return
You can escape recursion by using the return keyword. The return keyword is used to halt the execution of a function and return control to the caller function. Return is the key phrase needed to exit recursion. The process or function is terminated instantly with the void exit () keyword.