break and continue in when

Kotlin 1.3.60 (1.4 preview)

// process(listOf(1,2,3,0,4,-1,10)) == 1234
fun process(list: List<Int>) { 
  for (i in list) { 
    when (i) { 
      0 -> continue
      -1 -> break
      else -> print(i)
    }
  }
}

Back Home Next