Presentation on logical_operators

14
Logical Operators ICT Level V COT - Jaffna 1 S.Sakthybaalan

Transcript of Presentation on logical_operators

Page 1: Presentation on logical_operators

1

Logical Operators

ICT Level VCOT - Jaffna

S.Sakthybaalan

Page 2: Presentation on logical_operators

05/01/20232

Operator An operator is a symbol that tells the compiler to perform

specific mathematical or logical manipulations.

C# is rich in built-in operators and provides the following kinds of operators:

Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Misc Operators

Page 3: Presentation on logical_operators

05/01/20233

OperatorsArithmetic Operators

Relational Operators

Bitwise Operators

Assignment Operators

Misc Operators

Logical Operators

Page 4: Presentation on logical_operators

05/01/20234

Logical Operators (Conditional Operators) Logical operators allows you to combine multiple

conditions.

These operators involves at least two conditions and the final Boolean result is determined by the operator being used.

AND

OR

XOR

NOT

Logical Operators

Page 5: Presentation on logical_operators

05/01/20235

Operand and Operators In all computer languages, expressions consist of two types of

components: operands and operators.

Operands are the objects that are manipulated.

Operators are the symbols that represent specific actions. example:

5 + x Note: All expressions have at least one operand.

operator

operands

Page 6: Presentation on logical_operators

05/01/20236

AND Operator (&&) The AND operator is used to compare two Boolean values.

It returns true if both of the operands are true.

a b Result (AND)

0 0 00 1 01 0 01 1 1

0 – false

1 - true

Page 7: Presentation on logical_operators

05/01/20237

AND Operator in Programmingname = "Steven";

password = "Steven123";   // evaluating both expression and returns true if all are true.         if (name == "Steven" && password == "Steven123")

{ MessageBox.Show("Login Successful");}

else

{         MessageBox.Show "Unauthorised access");

}         

Page 8: Presentation on logical_operators

05/01/20238

OR Operator (||) The OR operator is similar to AND, as it is used to

compare two Boolean values.

The OR operator returns true if either of the operand(s) are true.

a b Result (OR)

0 0 00 1 11 0 11 1 1

}0 – false

1 - true

Page 9: Presentation on logical_operators

05/01/20239

OR Operator in Programming

string username, password;           if ((username == "Steven" || username == “Clark")

&& (password == "Steven123")){ MessageBox.Show("Login Successful");}

else

{         MessageBox.Show("Unauthorised access");

}         

Page 10: Presentation on logical_operators

05/01/202310

NOT Operator (!) The NOT operator is a unary operator, as it operates on a

single operand.

The NOT operator inverts the value of a Boolean value.

If the original value is true then the returned value is false; if the original value is false, the return value is true.

a Result (NOT)

0 11 0

0 – false

1 - true

Page 11: Presentation on logical_operators

05/01/202311

NOT Operator in Programmingname = "Steven";password = "Steven123";   // evaluating both expression and returns true if all are true.         if ( !(name == "Steven" && password == "Steven123"))

{ MessageBox.Show("Login Successful");}

else{ MessageBox.Show("Unauthorised access. Aborting…");}

         

Page 12: Presentation on logical_operators

05/01/202312

XOR Operator (^) It returns false if the following condition matches:

(i) if both or all the expression returns true.

(ii) If both or all the expression returns false.

a b Result (XOR)

0 0 00 1 11 0 11 1 0

0 – false

1 - true

Page 13: Presentation on logical_operators

05/01/202313

XOR Operator in Programmingstring name, password;

 name = "Steven" ;

password = "Steven123" ;

 //it returns false because both expression match.          if ((name == "Steven" ^ password == “Clark")

{

MessageBox.Show(“Access granted…");

}

else

{           MessageBox.Show (“Access Denied. Aborting…”);

}         

Page 14: Presentation on logical_operators

05/01/202314