Switches in Lua

Hello!

I am CPP programmer, and I’ve came back Lua. I like to use switch statements instead of multiple ‘else if’ statements in CPP. So I was just wandering, does a similar keyword exist? If yes, format the code below:

local n = 1

if n==0 then
    print("Number is 0.")
elseif n==1 then
    print("Number is 1.")
elseif n==2 then
    print("Number is 2.")
elseif n==3 then
    print("Number is 3.")
end

Thanks for answering.

nope

there are some modules that try to replicate switch statements but they don’t provide any ‘real’ advantages

try sticking with if statements on lua

1 Like

Mmmm, Alright then. I will try to stick with if statements.

1 Like