This chapter is all about control structures, like if statements, switch blocks, loops, and breaks. Specifically, we’ll look at the following:
- Conditionals like if statements, ternary expressions, and switches.
- Looping structures: do, while and for
- Breaking control flow.
- Exceptions, briefly.
Conditionals
Ifs and Ternaries
Conditionals
are straightforward.
// java
if (age > 55) {
retire();
} else {
carryOnWorking();
}
An if in Java looks exactly the same in Scala.
// scala
if (age > 55) {
retire()
} else {
carryOnWorking()
}
You’ll often find Scala developers dropping the ...