While I enjoy programming in Scala, there are some weird surprises from time to time …

For instance, take the break statement in Java (a control statement to break from a loop) … couldn’t be more simpler to use.

But in Scala? It’s verbose, only added recently as of versions 2.8+, and not implicitly in scope

import scala.util.control._

breakable {
for (...) {
if (some_condition) break
}
}

And to break from a nested loop, the code is even more verbose:

import scala.util.control._

val outer = new Breaks
val inner = new Breaks

outer.breakable {
for (...) {
// do something
inner.breakable {
for (...) {
if (some_condition) inner.break
}
}
// do something else
}
}

Bah! What gives Scala?