Chapter 8
Loops
We saw in chapter 6 how we could use recursion to produce an iterative behavior where something was done multiple times. We also saw in chapter 7 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.
8.1 while Loop
The most basic ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access