Jump to content

Difference between "and" and "not"


Hero192

Recommended Posts

All three words: or, and and not may be seen as logical gates. The first two are placed in between two statements that can be either true or false while not just negate whatever statement it's placed in front of. Consider the two lists below with 4 possible outcomes where 1 is true and 0 is false, last number is the result.

AND:

0 and 0 = 0

0 and 1 = 0

1 and 0 = 0

1 and 1 = 1

OR:

0 or 0 = 0

0 or 1 = 1

1 or 0 = 1

1 or 1 = 1

NOT:

not 0 = 1

not 1 = 0

So your example code would be considered as true if source is defined (could be anything except nil or false) or if source is an element. If you replace or with and however both the statements has to be true in order for the result to be true, ie. source must not be nil or false but source must also be an element, if source is not an element the result is false. Hopefully all this makes sense, it's all about basic logic.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...