Kotlin when Statement
Kotlin when Statement
In Kotlin, when is used for decision making. It is an advanced and more powerful replacement for the traditional switch statement.when can be used as a statement or as an expression.
1. Simple when Example
2. when as an Expression (Return Value)
3. Multiple Conditions in One Branch
4. Using Ranges in when
5. when Without Argument
Used as an alternative to if-else ladder.
6. when with Strings
7. when with Boolean
8. Smart Cast in when
Summary
-
whenreplacesswitch -
Can be used as statement or expression
-
Supports ranges, multiple values, types, and conditions
-
Cleaner and more powerful than
if-else
