61 posts / categories / feed

Basic Lua Programming with Conditional Statement

Conditional Statement in Lua

This is pretty similar to the majority of the languages.

Conditional Statement with String

local today = "sunday";
if (today == "sunday") then
    print("Yippee no school!");
elseif (today == "friday") then
    print("Hurray! Last school day for the week");
else
    print("school days!");
end

Conditional Statement with Numeric

local result = 79;
local grade;
if (result == 100) then
    print("Distinction!");
elseif (result >= 80 and result < 100) then
    print("Great!");
elseif (result > 50 and result < 80) then
    print("Credit");
else
    print("More practice required!");
end

-- check if grade is assigned or set
if (not grade) then
   print("Is this in grade or score?");
end