티스토리 뷰

공부

[scala] match case (switch case)

승가비 2023. 2. 10. 22:22
728x90
i match {
    case 1  => println("January")
    case 2  => println("February")
    case 3  => println("March")
    case 4  => println("April")
    case 5  => println("May")
    case 6  => println("June")
    case 7  => println("July")
    case 8  => println("August")
    case 9  => println("September")
    case 10 => println("October")
    case 11 => println("November")
    case 12 => println("December")
    // catch the default with a variable so you can print it
    case whoa  => println("Unexpected case: " + whoa.toString)
}

https://alvinalexander.com/scala/how-to-use-scala-match-expression-like-switch-case-statement/

 

How to use a Scala match expression like a switch statement | alvinalexander.com

This is an excerpt from the 1st Edition of the Scala Cookbook (partially modified for the internet). This is Recipe 3.7, “How to use a Scala match expression like a switch statement.” Problem You have a situation in your Scala code where you want to cr

alvinalexander.com

 

728x90
댓글