Control Flow
If Expressions
Choose a value with an if expression.
If Expressions
IfExpression.scala
object Main {
def main(args: Array[String]): Unit = {
val temperature =
val status = if (temperature >= 75) {
"warm"
} else {
"cool"
}
println("temperature=" + temperature)
println("status=" + status)
}
}
object Main {
def main(args: Array[String]): Unit = {
val temperature =
val status = if (temperature >= 75) {
"warm"
} else {
"cool"
}
println("temperature=" + temperature)
println("status=" + status)
}
}
object Main {
def main(args: Array[String]): Unit = {
val temperature =
val status = if (temperature >= 75) {
"warm"
} else {
"cool"
}
println("temperature=" + temperature)
println("status=" + status)
}
}
if-expression
An if expression chooses one of two values. The chosen value can be assigned to a name.