Our first program will demonstrate the use of if/else statements in Lua. Here’s the full source code:
To run the program, save the code in a file named if_else.lua and use the Lua interpreter:
Note that in Lua, you don’t need parentheses around conditions, but you do need to use then and end to define the scope of the if statement. The elseif keyword is used for additional conditions.
Lua doesn’t have a ternary operator, so you’ll need to use a full if statement even for basic conditions.