Lesson 5 of 15

If / Elseif / Else

Conditional Statements

Lua uses if, elseif, else, and end:

local x = 10

if x > 0 then
  print("positive")
elseif x < 0 then
  print("negative")
else
  print("zero")
end

Comparison Operators

  • == (equal), ~= (not equal)
  • <, >, <=, >=

Logical Operators

  • and, or, not
if x > 0 and x < 100 then
  print("between 1 and 99")
end

Your Task

Write a function that classifies a number as "positive", "negative", or "zero".

JS Transpiler loading...
Loading...
Click "Run" to execute your code.