Kotlin

Kotlin When Statement Example1 min read

Kotlin when statement is same as Java’s Switch statement. When statement in Kotlin allows a variable to be tested for equality against a list of values.

If none of the branch conditions are satisfied it will return the value of else branch.




For when statement it is not mandatory to use expression.In the above example, first program we used when as an expression. However, in the second operator enter it’s is not using an expression. Refer the above program for more understanding.

Kotlin Code:

Output:

Leave a Comment