As a Roblox developer, it would be convenient to have access to a
switch keyword like in a lot of other languages.
If Roblox is able to address this issue, it would improve my development experience by allowing me to keep my code neater and more compact.
Old syntax (cannot work)
Here is an example of the switch keyword vs without:
switch myVariable case "abc123": print("Value was abc123") break default: print("Value was something else") end if myVariable == "abc123" then print("Value was abc123") else print("Value was something else") end
switch myValue case nil: print("Value was nil, allow?") break case false: print("Value was false, error?") break default: print(myValue) end
Latest syntax proposed (better described in my reply):
switch value for "a" do -- Case a -- Code -- No break, so fall through end for "b" do -- Case for b -- Code break -- No fall through, so a or b will run this code end for "a", "b", "c" do -- Case for a, b or c -- Code break end do -- Default case (which has no for statement and no values because it's what occurs when there isn't a value. You could have a for keyword before, however I think this makes more sense and would allow for more confident case value syntax) -- Code end end