There are 4 main logical operators which
may be used in algorithms (programs)...
Examples :
If NOT (x = 100) then
output(message)
means that the
message will be output if the value of x is not equal to 100.
If (x > 19) AND (x < 50) then output(message)
means that the message will be output if both conditions (x >
19) and (x < 50) are true...ie if x lies
in the range 20..49 (inclusive).
Truth Table for AND
:
AND |
True |
False |
True |
True |
False |
False |
False |
False |
If (x < 20) OR (y
< 30) then output(message)
means that the message will be output if one or other (or both) of the conditions (x < 20) or (y < 30) are
true.
Truth Table for OR
:
OR |
True |
False |
True |
True |
True |
False |
True |
False |
If (x < 20) XOR (y
< 30) then output(message)
would output the message if one or
other (but not both) of the conditions (x < 20) or (y
< 30) are true.
Truth Table for XOR
:
XOR |
True |
False |
True |
False |
True |
False |
True |
False |
|