Skip to main content

Switch Statement

The switch statement consists of the following new keywords:

  • case
  • switch
  • default

Any variable or object can be used for the case statement, but you cannot use expressions like 1 == 1 in them.

Example Code
local value = 3switch value do  case 1:  case 2:  case 3:  case 4:  case 5:    print("Got 1-5.")    break  default:    print("Value is greater than 5.")end-- Break jumps here.

The default case will run if you don't break from any prior case expressions.

Using Compatibility Mode?

You may need to use pluto_switch instead of switch.

Interactive Example