9951 explained code solutions for 126 technologies


luaUsing switch...case


Since there's no switch statement in Lua, we'll use else/if:

if      var == 1 then print('1')
elseif  var == 2 then print('2')
elseif  var == 3 then print('3')
elseif  var == 4 then print('4')
else                  print('other')
endctrl + c
var

variable to check values of

elseif

we can use as many elseifs as we need


Usage example

var = 3
if      var == 1 then print('1')
elseif  var == 2 then print('2')
elseif  var == 3 then print('3')
elseif  var == 4 then print('4')
else                  print('other')
end
output
3