Checking whether a game board is full I have a method in Scala that checks if a game board is full or not. To speed this method up, I return inside the nested for loop to break out of both of them and stop execution. How would I achieve this in Scala in an idiomatic way?

def isFull: Boolean = {
  for (x &lt;- getGrid.indices) {
    for (y &lt;- getGrid(x).indices) {
      if (getGrid(x)(y).getState.isInstanceOf[Undecided]) {
        return false
      }
    }
  }
  true
}
You can apply forall to most containers to test if every element in the container satisfies some property. forall will only evaluate x + 1 if x is true. This type of evaluation is known as short-circuit evaluation. So basically we can use this property to perform the same behavior as the if-then statement in the original code.

Notice also that I've used pattern matching to get rid of the isInstanceOf[T]. 

def isFull: Boolean =
  getGrid.indices.forall(x =&gt;
    getGrid(x).indices.forall(y =&gt;
      getGrid(x)(y).getState match {
        case xyState: Undecided =&gt; False
        case _ =&gt; True
      }
    )
  )