본문

170621(수) - Kotlin docs (Return and Jumps)

Kotlin docs


Return and Jumps


- return

val s = person.name ?: return


- break

- continue



Break and Continue labels

loop@ for (i in 1..100) {

// ...

}


loop@ for (i in 1..100) {

for (j in 1..100) {

if (...) break@loop

}

}



Return at Labels

fun foo() {

ints.forEach {

if (it == 0) return 

print(it)

}

}


fun foo() {

ints.forEach lit@ {

if (it == 0) return@lit

print(it)

}

}


fun foo() {

ints.forEach {

if (it == 0) return@forEach

print(it)

}

}


fun foo() {

ints.forEach(fun(value: Int) {

if (value == 0) return 

print(value)

})

}


return@a 1


공유

댓글