Using When as an Expression Returning a Value in Kotlin
📖 Scenario: You are creating a simple program that assigns a message based on a day number. This is like checking the day of the week and giving a friendly note.
🎯 Goal: Build a Kotlin program that uses when as an expression to return a message string based on a day number.
📋 What You'll Learn
Create an integer variable
day with the value 3Create a variable
message that uses when as an expression to assign a string based on dayUse
when with cases for days 1 to 7, returning the correct day namePrint the
message variable💡 Why This Matters
🌍 Real World
Using <code>when</code> expressions helps in apps to decide actions based on user input or data values, like showing messages or choosing options.
💼 Career
Understanding <code>when</code> expressions is important for Kotlin developers to write clean and readable decision-making code.
Progress0 / 4 steps