Chapter 4

Conditionals

We solved some basic problems in the last chapter, but the techniques that we have access to are fundamentally limited at this point. The real problem is that all the lines in a script execute in the same order from top to bottom every time the script is run. In most real problems we need to be able to do what is called conditional execution, where something happens only in certain situations. In this chapter we will learn the most fundamental method for doing conditional execution in Scala and see how we can use it to solve more complex problems.

In order to do this properly, we need to develop a formalized way to express logic and put it into our programs. This system, called Boolean logic, will allow us to state the ...

Get Introduction to the Art of Programming Using Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.