Lua Conditional contexts


Example

Conditional contexts in Lua (if, elseif, while, until) do not require a boolean. Like many languages, any Lua value can appear in a condition. The rules for evaluation are simple:

  1. false and nil count as false.

  2. Everything else counts as true.

    if 1 then
      print("Numbers work.")
    end
    if 0 then
      print("Even 0 is true")
    end
    
    if "strings work" then
      print("Strings work.")
    end
    if "" then
      print("Even the empty string is true.")
    end