logical operators: With (&&) or (| | ) Non (. )
, "&&" and "| |" is called a short-circuit operator
and , "&" and "|" Known as a non-short-circuit operator (less used, logically unreasonable)
The difference between a short-circuit operator and a non-short-circuit operator:
short-circuit operator : [Condition 1 && Condition 2], if condition 1 is not tenable, condition 2 does not perform a non-short-circuit operator : [Condition 1 && Condition 2], regardless of condition 1, continue to execute condition 2
For example: Execute short-circuit operator, code:
int a=1;
int b=2;
if (a==1 && b++==3) {
System.out.println ("Conditional 1,2 set up");
}
System.out.println (b);
Result output:
2
To perform a non-short-circuit operator code:
int a=1;
int b=2;
if (A==1 & b++==3) {
System.out.println ("Conditional 1,2 set up");
}
System.out.println (b);
Result output:
3
or ("| |") and "|" Empathy
The main difference is that
"&&" and "&"
Condition 1 if not established, continue to execute condition 2
"| |" and "|"
Condition 1 if not established, continue to execute condition 2