Using logical operators to connect relational expressions or Boolean expressions is a logical expression. The value of the logical expression is still a Boolean value.
In the evaluation of a logical expression, not all logical operators are executed. Sometimes, you can determine the result of a logical expression without having to execute all the operators. You continue to execute a logical expression only if the next logical operator must be executed before it can be evaluated. In this case we call the "short-circuit" of the logical expression.
Suppose A is a Boolean value or a logical expression, and bool-exp is a logical expression, then:
a&& (BOOL-EXP) continues to judge values only if a is true. If A is false, the value of the logical expression is already set to false and no further evaluation is required.
a| | (BOOL-EXP) only if A is false will the value continue to be judged. If A is true, the value of the logical expression is already determined to be true and no further evaluation is required.
After mastering logical operators and relational operators skillfully, you can use logical expressions to represent various complex conditions. For example, give a year to determine whether it is a leap month. We know that the terms of a leap year are: multiples of 400, or multiples of 4 but not multiples of 100. Year is set, and leap years or not can be represented by a logical expression:
(year%400) ==0| | ((year%4) ==0&& (year%100)!=0)