xxxxxxxxxx
val num = 10
if (num > 0) {
println("Number is positive")
} else if (num < 0) {
println("Number is negative")
} else {
println("Number is zero")
}
xxxxxxxxxx
fun main(args: Array<String>) {
val number = -10
val result = if (number > 0) {
"Positive number"
} else {
"Negative number"
}
println(result)
}
xxxxxxxxxx
if (testExpression) {
// codes to run if testExpression is true
}
else {
// codes to run if testExpression is false
}
xxxxxxxxxx
val dayOfWeek = "Monday"
when (dayOfWeek) {
"Monday" -> println("It's the start of the workweek")
"Saturday", "Sunday" -> println("It's the weekend")
else -> println("It's a regular weekday")
}
xxxxxxxxxx
val number = -5
if (number > 0) {
println("Positive")
} else if (number < 0) {
println("Negative")
} else {
println("Zero")
}