Is there something equivalent to when statement from kotlin

Is there something equivalent to the when statement from kotlin?
or is swiftt old and only has switch ?

I think you might be looking for while.

var a = 100

while (a > 10) {
    //add your code to run within the loop

Refer: Documentation

Hi @aktive, in Swift the equivalent to Kotlin's when is known as switch. You can read more about it here:

1 Like

so theres nothing modern, just old switch?

Swift’s switch statement doesn’t work in exactly the same way as switch statements in other languages like C/C++/Java — it is more “modern”.

In Swift, switch statements do not implicitly fall through. This means that you do not have to put break at the end of each switch case like you have to to in C/C++/Java.

Additionally, switch statements in Swift are required to be exhaustive. That means that a switch must have cases to handle every possible input, or it must have a default clause.

Another feature that Swift switches have is pattern matching, which allows for more powerful cases.

For more information, I recommend checking out the link xwu shared.

Think what you’re looking for is pattern matching. Swift just use ‘switch’ word for that, think lately Java also did that.