ABSTRACT

We saw in chapter 5 how we could use recursion to produce an iterative behavior where something was done multiple times. We also saw in chapter 6 that we can use collections to make certain operations happen multiple times. These approaches are the primary methods used in functional languages, and they often work well to provide the functionality we need in Scala. Most languages, including Scala, provide other constructs called loops that are designed specifically for creating this iterative behavior. In this chapter we will explore the loop structures present in Scala and see how we can use these in our programs. We will start by repeating some of the things that we did previously using recursion.