ABSTRACT

Gaining conditionals provided us with a lot of power, we can express more complex logic in our code. Adding functions gave us the ability to break problems into pieces and reuse functionality without retyping code. There is still something very significant that we are missing. Currently, when we write a piece of code, it happens once. We can put that code into a function and then call the function over and over, but it will only happen as many times as we directly call it. We cannot easily vary the number of times that something happens, or make anything happen a really large number of times. This is a problem, because one of the things that computers are really good at is doing the same thing many times without getting bored or distracted. The is a capability that we really need to add to our toolbox. There is more than one way to make something happen multiple times in Scala. One of these ways, recursion, we can do with just functions and conditionals, constructs that we have already learned.