Fragmented - Android Developer Podcast

150: Learning Kotlin - Returns, Jumps & Labels

Informações:

Sinopse

Shownotes Kotlin Returns and Jumps Documentation Code data class Customer(val isPlatinum: Boolean) fun main() { val customer = Customer(false) println("Number of points customer has: ${calculatePoints(customer)}") // Break out of the loop once we're over 25 for (i in 1..100) { if (i > 25) { break } else { println(i) } } // Skip all even numbers for (i in 1..100) { if (i % 2 == 0) { continue } else { println(i) } } // Break out of the outer loop (which breaks out of the inner too) using a label donn@ for (i in 1..100) { for (j in 100..200) { if (j > 150) break@donn // This will break out of the inner loop and outer loop else println("i: $i, j: $j") } } // Continue processing the next outer loop value when a condition is met. donn@ for (i in 1..100) { for (j in 100..200) {