O'Reilly logo

Introduction to the Art of Programming Using Scala by Mark C. Lewis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6

Recursion for Iteration

Gaining conditionals provided us with a lot of power. We are now able to express logic in our code. Adding functions gave us the ability to break problems into pieces and repeat functionality without retyping code. There is still something very significant that we are missing. Now when we write a piece of logic, it happens once. We can put that logic into a function and then call the function over and over, but it will only happen as many times as we call it. We can not easily vary the number of times that something happens. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required