Search code examples
luaconditional-statementsternary

Inline conditions in Lua (a == b ? "yes" : "no")?


Is there anyway to use inline conditions in Lua?

Such as:

print("blah: " .. (a == true ? "blah" : "nahblah"))

Solution

  • Sure:

    print("blah: " .. (a and "blah" or "nahblah"))