[go: up one dir, main page]

0% found this document useful (0 votes)
15 views2 pages

2.boolean Logic

Boolean logic uses operators like AND, OR, and NOT to evaluate expressions and produce true or false values. The AND operator returns true only if both conditions are true, the OR operator returns true if at least one condition is true, and the NOT operator reverses the result of a condition. Examples illustrate how these operators function with given variable values.

Uploaded by

pme6901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

2.boolean Logic

Boolean logic uses operators like AND, OR, and NOT to evaluate expressions and produce true or false values. The AND operator returns true only if both conditions are true, the OR operator returns true if at least one condition is true, and the NOT operator reverses the result of a condition. Examples illustrate how these operators function with given variable values.

Uploaded by

pme6901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Boolean logic

Boolean logic takes two statements or expressions and applies a logical operator to generate a
Boolean value that can be either true or false. To return the result, operators like AND, OR, NOT,
etc. are used.

There are three basic Boolean operators, AND, OR, and NOT

1. AND operator (&&)


2. OR operator (| |)
3. NOT operator (!)

1. AND Operator (&&)

The symbol used for AND operator is (&&). It is used to evaluate two conditions. It produces true
result if both conditions are true. It produces false result if any one condition is false.

Example

Suppose we have two variables A = 100 and B = 50. The compound condition (A>10) && (B>10)
is true. It contains two conditions and both are true. So the whole compound condition is also
true.

The compound condition (A>50) && (B>50) is false. It contains two conditions. One condition
(A > 50) is true and second condition (B>50) is false. So the whole compound condition is false.

Notes by: Mariam Tariq


2. OR Operator ( | | )

The symbol used for OR operator is ( | | ). It is used to evaluate two conditions. It produces true
result if either condition is true. It gives false result if both conditions are false.

Example

Suppose we have two variables A=100 and B=50. The compound condition (A>50) || (B>50) is
true. It contains two conditions and one condition (A>50) is true. So the whole compound
condition is also true. The compound condition (A>500) || (B>500) is false because both
conditions are false.

3. NOT Operator (!)

The symbol used for NOT operators (!). It is used to reverse the result of a condition. It gives true
result if the condition is false. It gives false result if the condition is true.

Example

Suppose we have two variables A = 100 and B = 50. The condition !(A==B) is true. The result of
(A==B) is false but NOT operator converts it into true. The condition !(A>B) is false. The
condition (A > B) is true but NOT operator converts it into false.

Notes by: Mariam Tariq

You might also like