blob: e89a03f76b0d6725125a4c5a8ceb8ae01b1d05c7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package scalax.util.control
object Breaks {
private class BreakException extends RuntimeException
private val breakException = new BreakException
private class ContinueException extends RuntimeException
private val continueException = new ContinueException
/** A block from which one can exit with a `break' and which can be resumed with a `continue'. */
def breakable(op: => Unit) {
try {
op
} catch {
case ex: BreakException =>
case ex: ContinueException => breakable(op)
}
}
/* Break from closest enclosing breakable block */
def break { throw breakException }
/* Continue with start of closest enclosing breakable block */
def continue { throw continueException }
}
|