View Single Post
10-27-16, 06:39 PM   #4
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Lua Code:
  1. firstArgument = true
  2. secondArgument = false
  3.  
  4. if not (firstArgument and secondArgument) then print(1)
  5.     -- This is true, because the arguments in the
  6.     -- parenthesis are resolved first.
  7.     -- Since secondArgument is false, the overall outcome inside
  8.     -- the parenthesis will also be false.
  9.     -- Once it gets back outside the parenthesis, the statement is negated,
  10.     -- meaning it results in the reverse value of the parenthesis outcome.
  11. end
  12.  
  13. if not firstArgument and secondArgument then print(2)
  14.     -- This is false, because the keyword 'not' will in this case
  15.     -- negate the firstArgument, but has no effect on the secondArgument.
  16. end
  17.  
  18. if firstArgument and not secondArgument then print(3)
  19.     -- This is true, because the secondArgument will be negated into true,
  20.     -- and since firstArgument is also true, the overall outcome is true.
  21. end
  22.  
  23. if (not firstArgument and secondArgument) then print(4)
  24.     -- This is false, because it's not any different from the second
  25.     -- example. Since nothing affects the if-case outside the
  26.     -- parenthesis, it'll result in the same outcome.
  27. end
  28.  
  29. if not (not firstArgument and secondArgument) then print(5)
  30.     -- This is true, because the parenthesis returns false, which is then
  31.     -- negated into true. firstArgument is negated into false, consolidated
  32.     -- with secondArgument into false again, and then negated into true.
  33. end
  34.  
  35. if firstArgument or secondArgument then print(6)
  36.     -- This is true, because the firstArgument is true.
  37.     -- If either argument is true when using 'or', it'll result in true,
  38.     -- even if one or more arguments are false.
  39. end
  40.  
  41. if secondArgument or firstArgument then print(7)
  42.     -- This is true all the same, because even though secondArgument is
  43.     -- checked first, firstArgument is still true and thus the outcome is true.
  44. end
  45.  
  46. if secondArgument or not firstArgument then print(8)
  47.     -- This is false, because both arguments will be false.
  48.     -- secondArgument is already false, and firstArgument is negated into false,
  49.     -- as explained in the second example.
  50. end
  51.  
  52. if ( firstArgument and not secondArgument) or (not firstArgument and secondArgument) then print(9)
  53.     -- The first parenthesis results in true, the second parenthesis results in false.
  54.     -- Since either argument will do, because we're using 'or', the result is true.
  55. end
__________________
  Reply With Quote