fork(1) download
  1. --,___________________________________________________________________,
  2. --| *NOTE* - Because nil cannot be accurately represented in a string |
  3. --| without actually typing 'nil' or '', some of the output may |
  4. --| seem a little misleading... But the point is to understand |
  5. --| the meaning behind the relational "negation of equality" |
  6. --| operator, found at: http://w...content-available-to-author-only...a.org/pil/3.2.html |
  7. --`-------------------------------------------------------------------'
  8.  
  9.  
  10. --[[-------------------------------------
  11. --Test #1: Check if NOT nil
  12. --]]-------------------------------------
  13. print("--[ Test #1: Check if NOT nil ]--")
  14.  
  15. local value = nil
  16. if(value ~= nil) then
  17. print("a.) ["..tostring(value).."] is NOT nil")
  18. else
  19. print("a.) ["..tostring(value).."] is nil")
  20. end
  21.  
  22. value = ''
  23. if(value ~= nil) then
  24. print("b.) [\""..tostring(value).."\"] is NOT nil")
  25. else
  26. print("b.) [\""..tostring(value).."\"] is nil")
  27. end
  28.  
  29. value = 'string'
  30. if(value ~= nil) then
  31. print("c.) [\""..tostring(value).."\"] is NOT nil")
  32. else
  33. print("c.) [\""..tostring(value).."\"] is nil")
  34. end
  35.  
  36. print("\n")
  37.  
  38. --[[-------------------------------------
  39. --Test #2: Check if NOT empty
  40. --]]-------------------------------------
  41. print("--[ Test #1: Check if NOT empty ]--")
  42.  
  43. value = nil
  44. if(value ~= '') then
  45. print("a.) ["..tostring(value).."] is NOT empty")
  46. else
  47. print("a.) ["..tostring(value).."] is empty")
  48. end
  49.  
  50. value = ''
  51. if(value ~= '') then
  52. print("b.) [\""..tostring(value).."\"] is NOT empty")
  53. else
  54. print("b.) [\""..tostring(value).."\"] is empty")
  55. end
  56.  
  57. value = 'string'
  58. if(value ~= '') then
  59. print("c.) [\""..tostring(value).."\"] is NOT empty")
  60. else
  61. print("c.) [\""..tostring(value).."\"] is empty")
  62. end
  63.  
  64. print("\n")
  65.  
  66. --[[-------------------------------------
  67. --Test #3: Check if NOT nil AND NOT empty
  68. --]]-------------------------------------
  69. print("--[ Test #1: Check if NOT nil AND NOT empty ]--")
  70.  
  71. value = nil
  72. if(value~=nil and value~='') then
  73. print("a.) ["..tostring(value).."] is NOT nil AND NOT empty")
  74. else
  75. print("a.) ["..tostring(value).."] is nil AND empty")
  76. end
  77.  
  78. value = ''
  79. if(value~=nil and value~='') then
  80. print("b.) [\""..tostring(value).."\"] is NOT nil AND NOT empty")
  81. else
  82. print("b.) [\""..tostring(value).."\"] is nil AND empty")
  83. end
  84.  
  85. value = 'string'
  86. if(value~=nil and value~='') then
  87. print("c.) [\""..tostring(value).."\"] is NOT nil AND NOT empty")
  88. else
  89. print("c.) [\""..tostring(value).."\"] is nil AND empty")
  90. end
  91.  
  92. print("\n")
  93.  
  94. --[[-------------------------------------
  95. --Test #4: Check if NOT nil OR NOT empty
  96. --]]-------------------------------------
  97. print("--[ Test #1: Check if NOT nil OR NOT empty ]--")
  98.  
  99. value = nil
  100. if(value~=nil or value~='') then
  101. print("a.) ["..tostring(value).."] is NOT nil OR NOT empty")
  102. else
  103. print("a.) ["..tostring(value).."] is nil OR empty")
  104. end
  105.  
  106. value = ''
  107. if(value~=nil or value~='') then
  108. print("b.) [\""..tostring(value).."\"] is NOT nil OR NOT empty")
  109. else
  110. print("b.) [\""..tostring(value).."\"] is nil OR empty")
  111. end
  112.  
  113. value = 'string'
  114. if(value~=nil or value~='') then
  115. print("c.) [\""..tostring(value).."\"] is NOT nil OR NOT empty")
  116. else
  117. print("c.) [\""..tostring(value).."\"] is nil OR empty")
  118. 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