Skip to content

improvement:operators.md #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lessons/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ Relational operators are used to compare the values of two operands. They are us

Logical operators are used to perform logical operations. They are used to perform the following operations:

- `&&`: AND used to perform logical AND operation. It gives true if both the operands have true value.
- `||`: OR used to perform logical OR operation. It gives true if either of the operands have true value.
- `&&` 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.

- `||` 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.
- `!`: NOT used to perform logical NOT operation. It gives true if the operand has false value.

let's see an example:
Expand Down