Skip to content

Instantly share code, notes, and snippets.

@renaudcerrato
Last active March 12, 2019 12:20
Show Gist options
  • Save renaudcerrato/f953cf6d01fbfb95a1d370175b234df3 to your computer and use it in GitHub Desktop.
Save renaudcerrato/f953cf6d01fbfb95a1d370175b234df3 to your computer and use it in GitHub Desktop.
Kotlin Return with Labels
val list = listOf("Kotlin", "", "Java", "Groovy")
fun main() {
list.forEach {
if(it.isNullOrEmpty()) return@forEach // return with implicit label
println(it)
}
println("Done!")
}
// equivalent to:
fun main() {
list.forEach there@{ str ->
if(it.isNullOrEmpty()) return@there // return with explicit label
println(str)
}
println("Done!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment