Skip to content

Instantly share code, notes, and snippets.

@eloraburns
Created January 20, 2015 15:13
Show Gist options
  • Save eloraburns/ee89b94f8602e25296d3 to your computer and use it in GitHub Desktop.
Save eloraburns/ee89b94f8602e25296d3 to your computer and use it in GitHub Desktop.
Scoping of "return" in Scala
scala> // "return" binds to the nearest method, not function literals.
scala> def myfun() {
| val foo = List(1, 2, 3);
| val bar = foo map { x =>
| println(x)
| if (x == 2) return
| }
| println("Dead code")
| }
myfun: ()Unit
scala> myfun
1
2
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment