In contrast to Java's switch
, the when
statement has no fall-through behavior. This means, that if a branch is matched, the control flow returns after its execution and no break
statement is required. If you want to combine the bahaviors for multiple arguments, you can write multiple arguments separated by commas:
when (x) {
"foo", "bar" -> println("either foo or bar")
else -> println("didn't match anything")
}