You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lessons/operators.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -70,8 +70,9 @@ Relational operators are used to compare the values of two operands. They are us
70
70
71
71
Logical operators are used to perform logical operations. They are used to perform the following operations:
72
72
73
-
-`&&`: AND used to perform logical AND operation. It gives true if both the operands have true value.
74
-
-`||`: OR used to perform logical OR operation. It gives true if either of the operands have true value.
73
+
-`&&` and `&`: Java unlike many other languages has two AND operators to perform logical AND operation. It returns true if both the operands (being compared) have a truthy value. Even though both the `&` and `&&` operators perform the same AND operation; the `&&` operator is a logical operator and it can improve the efficiency of your code since it evaluates the second expression only if the first expression is true unlike the bitwise `&` operator which evaluates the second expression nonetheless.
74
+
75
+
-`||` and `|`: OR is used to perform logical OR operation. It returns true if either of the operands have a truthy value. The difference between `|` and `||` is that the `|` operator is a bitwise operator and it compares each operand bitwise whereas the `||` operator is the logical OR operator. It operates on both the operands and returns true if either of the operands have a truthy value.
75
76
-`!`: NOT used to perform logical NOT operation. It gives true if the operand has false value.
0 commit comments