Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created January 31, 2015 08:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shigemk2/5b2c4d8da18a9c4da6d0 to your computer and use it in GitHub Desktop.
import util.control.Breaks._
println("\n=== BREAK EXAMPLE ===")
breakable {
for (i <- 1 to 10) {
println(i)
if (i > 4) break // break out of the for loop
}
}
println("\n=== CONTINUE EXAMPLE ===")
val searchMe = "peter piper picked a peck of pickled peppers"
var numPs = 0
for (i <- 0 until searchMe.length) {
breakable {
if (searchMe.charAt(i) != 'p') {
break // break out of the 'breakable', continue the outside loop
} else {
numPs += 1
}
}
}
println("Found " + numPs + " p's in the string.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment