Skip to main content
Close announcements banner

Switch-Case expressions

You can create switch expressions using the keywords switch, case and default. They evaluate the literals and return a value when a literal matches the switch expression, and can return a default value if none of the literals match the expression. You can specify multiple expressions for the same case, separated by , or ;. In this case, all expressions are evaluated if the condition is met, and the result of the last expression is returned.

These expressions should follow this syntax:
switch (expression1) {
	case literal1: expression2, expression3
	case literal2: expression4, expression5
	default: expression6
}
The following example is a valid switch expression:
switch (media) { 
	case "Star Wars": message = "May the Force be with you" 
	case "Star Trek": message = "Live long and prosper"
      default: "Cheers"
} 

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!