fork(1) download
--,___________________________________________________________________,
--| *NOTE* - Because nil cannot be accurately represented in a string |
--|       without actually typing 'nil' or '', some of the output may |
--|       seem a little misleading... But the point is to understand  |
--|       the meaning behind the relational "negation of equality"    |
--|       operator, found at: http://w...content-available-to-author-only...a.org/pil/3.2.html         |
--`-------------------------------------------------------------------'


--[[-------------------------------------
--Test #1: Check if NOT nil
--]]-------------------------------------
print("--[ Test #1: Check if NOT nil ]--")

local value = nil
if(value ~= nil) then
    print("a.) ["..tostring(value).."] is NOT nil")
else
    print("a.) ["..tostring(value).."] is nil")
end

value = ''
if(value ~= nil) then
    print("b.) [\""..tostring(value).."\"] is NOT nil")
else
    print("b.) [\""..tostring(value).."\"] is nil")
end

value = 'string'
if(value ~= nil) then
    print("c.) [\""..tostring(value).."\"] is NOT nil")
else
    print("c.) [\""..tostring(value).."\"] is nil")
end

print("\n")

--[[-------------------------------------
--Test #2: Check if NOT empty
--]]-------------------------------------
print("--[ Test #1: Check if NOT empty ]--")

value = nil
if(value ~= '') then
    print("a.) ["..tostring(value).."] is NOT empty")
else
    print("a.) ["..tostring(value).."] is empty")
end

value = ''
if(value ~= '') then
    print("b.) [\""..tostring(value).."\"] is NOT empty")
else
    print("b.) [\""..tostring(value).."\"] is empty")
end

value = 'string'
if(value ~= '') then
    print("c.) [\""..tostring(value).."\"] is NOT empty")
else
    print("c.) [\""..tostring(value).."\"] is empty")
end

print("\n")

--[[-------------------------------------
--Test #3: Check if NOT nil AND NOT empty
--]]-------------------------------------
print("--[ Test #1: Check if NOT nil AND NOT empty ]--")

value = nil
if(value~=nil and value~='') then
    print("a.) ["..tostring(value).."] is NOT nil AND NOT empty")
else
    print("a.) ["..tostring(value).."] is nil AND empty")
end

value = ''
if(value~=nil and value~='') then
    print("b.) [\""..tostring(value).."\"] is NOT nil AND NOT empty")
else
    print("b.) [\""..tostring(value).."\"] is nil AND empty")
end

value = 'string'
if(value~=nil and value~='') then
    print("c.) [\""..tostring(value).."\"] is NOT nil AND NOT empty")
else
    print("c.) [\""..tostring(value).."\"] is nil AND empty")
end

print("\n")

--[[-------------------------------------
--Test #4: Check if NOT nil OR NOT empty
--]]-------------------------------------
print("--[ Test #1: Check if NOT nil OR NOT empty ]--")

value = nil
if(value~=nil or value~='') then
    print("a.) ["..tostring(value).."] is NOT nil OR NOT empty")
else
    print("a.) ["..tostring(value).."] is nil OR empty")
end

value = ''
if(value~=nil or value~='') then
    print("b.) [\""..tostring(value).."\"] is NOT nil OR NOT empty")
else
    print("b.) [\""..tostring(value).."\"] is nil OR empty")
end

value = 'string'
if(value~=nil or value~='') then
    print("c.) [\""..tostring(value).."\"] is NOT nil OR NOT empty")
else
    print("c.) [\""..tostring(value).."\"] is nil OR empty")
end
Success #stdin #stdout 0.01s 2540KB
stdin
Standard input is empty
stdout
--[ Test #1: Check if NOT nil ]--
a.) [nil] is nil
b.) [""] is NOT nil
c.) ["string"] is NOT nil


--[ Test #1: Check if NOT empty ]--
a.) [nil] is NOT empty
b.) [""] is empty
c.) ["string"] is NOT empty


--[ Test #1: Check if NOT nil AND NOT empty ]--
a.) [nil] is nil AND empty
b.) [""] is nil AND empty
c.) ["string"] is NOT nil AND NOT empty


--[ Test #1: Check if NOT nil OR NOT empty ]--
a.) [nil] is NOT nil OR NOT empty
b.) [""] is NOT nil OR NOT empty
c.) ["string"] is NOT nil OR NOT empty