I hope to return to the line aa@ logError("Done")
outside forEach
, but return@aa
doesn't work, and break@label
doesn't work too.
And more, if you use return
, it will be return outside the fun lookForAlice
!
data class Person(val name: String, val age: Int)
val people = listOf(Person("Paul", 30), Person("Alice", 29), Person("Bob", 31))
fun lookForAlice(people: List<Person>) {
people.forEach label@{
logError("Each: "+it.name)
if (it.name == "Alice") {
logError("Find")
return@aa //It's fault
}
}
aa@ logError("Done")
}
lookForAlice(people)