Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/scala/internal/LoopUntil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ package internal
object LoopUntil extends App {

// define the new control-flow structure here
def loop_until(control: =>Boolean)(body: =>Unit) = {
while (!control) body
}

var i = 0

Expand Down
13 changes: 12 additions & 1 deletion src/main/scala/internal/RepeatUntil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ package internal
object RepeatUntil extends App {

// define the new control-flow structure here


class repeater(body: =>Unit) {
def until(control: =>Boolean) = {
do body while (!control)
}
}

def repeat(body: =>Unit) = {
new repeater(body)
}


var i = 0
repeat {
if ( (i % 2) == 0 )
Expand Down
17 changes: 16 additions & 1 deletion src/main/scala/internal/WhileContinue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ package internal
object WhileContinue extends App {

// define the new control-flow structures here

case class continueException(str:String) extends Exception(str)

def while_c(control: =>Boolean)(body: =>Unit) = {
while (control) {
try {
body
} catch {
case e: continueException => Nil
}
}
}

def continue = {
throw new continueException("")
}

var i = -1

while_c (i < 9) {
Expand Down