Using When with Multiple Conditions in Kotlin
📖 Scenario: You are creating a simple program to categorize a day of the week into different types based on the day name.
🎯 Goal: Build a Kotlin program that uses a when expression with multiple conditions to print the type of day.
📋 What You'll Learn
Create a variable called
day with the exact value "Tuesday".Create a variable called
weekendDays that holds the days "Saturday" and "Sunday".Use a
when expression with multiple conditions combined using commas to check if day is a weekend day or a weekday.Print the exact output based on the
when result.💡 Why This Matters
🌍 Real World
Categorizing days helps apps show different content or behavior on weekends versus weekdays, like special offers or schedules.
💼 Career
Understanding how to use <code>when</code> with multiple conditions is important for writing clear and concise Kotlin code in Android apps and backend services.
Progress0 / 4 steps