Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,2 +1,5 @@
|
|||
{{Control Structures}}
|
||||
In this task, we document common flow-control structures. One common example of a flow-control structure is the <tt>goto</tt> construct. Note that [[Conditional Structures]] and [[Iteration|Loop Structures]] have their own articles/categories.
|
||||
In this task, we document common flow-control structures.
|
||||
One common example of a flow-control structure is the <tt>goto</tt> construct.
|
||||
Note that [[Conditional Structures]] and [[Iteration|Loop Structures]]
|
||||
have their own articles/categories.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
import Goto._
|
||||
import scala.util.continuations._
|
||||
|
||||
object Goto {
|
||||
|
||||
case class Label(k: Label => Unit)
|
||||
|
||||
private case class GotoThunk(label: Label) extends Throwable
|
||||
|
||||
def label: Label @suspendable =
|
||||
shift((k: Label => Unit) => executeFrom(Label(k)))
|
||||
|
||||
def goto(l: Label): Nothing =
|
||||
throw new GotoThunk(l)
|
||||
|
||||
private def executeFrom(label: Label): Unit = {
|
||||
val nextLabel = try {
|
||||
label.k(label)
|
||||
None
|
||||
} catch {
|
||||
case g: GotoThunk => Some(g.label)
|
||||
}
|
||||
if (nextLabel.isDefined) executeFrom(nextLabel.get)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue