课程: Mastering Web Developer Interview Code

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

When would you use recursion?

When would you use recursion?

- [Instructor] Recursion is a programming technique that is popular among developers. So it can be a common question during interviews. Let's take a look at what it is, and more importantly, when it is useful. Now recursion sounds a lot fancier and more complicated than it really is, to put it simply, recursion happens anytime a function calls itself. Now that's a dangerous technique for obvious reasons. If you take a look at this example, you'll see that this function called myself, calls itself indefinitely. And this would happen until the computer runs out of memory. So at the very least every recursive function needs something called a base case. That's a statement that exits the function when a condition is met. You can see that in this simple example, we're using this function called countUp, the countUp from one to the number five. We're doing the recursion right here when this function called itself, with the…

内容