How to use short if in Scala

2 Answers

0 votes
object ShortIfExample {
  def main(args: Array[String]): Unit = {
    val age = 18
    
    val status = if (age >= 18) "Adult" else "Minor"
    
    println(status)
  }
}

  
     
/*
run:
  
Adult

*/

 



answered Apr 8, 2025 by avibootz
0 votes
object InlineIfExample {
  def main(args: Array[String]): Unit = {
    val age = 16
    
    println(if (age >= 18) "Adult" else "Minor") 
  }
}


  
     
/*
run:
  
Minor

*/

 



answered Apr 8, 2025 by avibootz
...