Ayden
08/30/2018, 6:28 AM-> in lamdas as return?diesieben07
08/30/2018, 6:29 AMAyden
08/30/2018, 7:00 AM@lit use for?Ayden
08/30/2018, 7:01 AM@filteredwardwongtl
08/30/2018, 7:02 AMreturn@filter, making a return to another scopeedwardwongtl
08/30/2018, 7:03 AMreturn will only return from the current function scope.Ayden
08/30/2018, 7:06 AMedwardwongtl
08/30/2018, 7:07 AMNon-local returnAyden
08/30/2018, 7:30 AMedwardwongtl
08/30/2018, 7:32 AMAyden
08/30/2018, 7:40 AMfun foo() {
    run loop@{
        listOf(1, 2, 3, 4, 5).forEach {
            if (it == 3) return@loop // non-local return from the lambda passed to run
            print(it)
        }
    }
    print(" done with nested loop")
}
12 done with nested loop
fun foo() {
    run {
        listOf(1, 2, 3, 4, 5).forEach {
            if (it == 3) return@forEach
            // non-local return from the lambda passed to run
            print(it)
        }
    }
    print(" done with nested loop")
}
1245 done with nested loopAyden
08/30/2018, 7:41 AMedwardwongtl
08/30/2018, 7:43 AMreturn@forEach actually work as continueAyden
08/30/2018, 8:46 AMcontinue or return@forEach right?
fun foo() {
    listOf(1, 2, 3, 4, 5).forEach lit@{
        if (it == 3) return@lit // local return to the caller of the lambda, i.e. the forEach loop
        print(it)
    }
    print(" done with explicit label")
}
fun main(args: Array<String>) {
    foo()
}Ayden
08/30/2018, 8:50 AMfun foo() {
    run loop@{
        listOf(1, 2, 3, 4, 5).forEach {
            if (it == 3) return@loop // non-local return from the lambda passed to run
            print(it)
        }
    } <- Here is the end of the local scope right?
    print(" done with nested loop")
}Ayden
08/30/2018, 8:50 AMAyden
08/30/2018, 8:51 AM12 done with nested loop is because the end of the local scope is after the close bracket of the run.Ayden
08/30/2018, 8:52 AMShawn
08/30/2018, 1:32 PM