kotlin return code example
Example 1: kotlin method return
fun sum(val a: Int, val b: Int): Int {
return a+b
}
fun sum(val a: Int, val b: Int) = a + b
Example 2: kotlin labels
fun onlyPrimes() {
// You can use labels to specify which loop will skip current iteration
outer@for (num in 2..100) {
for (check in 2..(num / 2)) {
if (num % check == 0) {
continue@outer
}
}
println(num)
}
}
Example 3: kotlin function return
fun sum(a: Int, b: Int): Int {
return a + b
}