1. What is a sentence of Wei?
The Wei statement is to express complex conditional expressionsSplit into multiple conditional expressions,Reduce nesting. Several layers of if - then-else statements are nested, converted into multiple if statements to implement its logic. These multiple if statements are Wei statements.
The Wei Statement prioritizes certain key conditions and simplifies the direction of the program process. Usa statements are often used to optimize if conditional nested code.
In the Alibaba Java Development Manual, mandatory provisions:More than 3 floors if-elseThe logical judgment code can be used in the Wei statement, policy mode, state mode, etc., among which the ward statement is the code logic that first considers the situation of direct return such as failure, exception, interrupt, exit, etc., and solves the problem of judging branches nesting in the code in a multiple exit method. This is the embodiment of reverse thinking.
2. Give an example
Nested statements are very cumbersome and have poor readability.
public void get(int t) {
if (t == 1) {
return;
} else {
if (t == 2) {
return;
} else {
if (t == 3) {
return;
} else {
set();
}
}
}
}
Use the harbor statement:
public void get(int t) {
if (t == 1) {
return;
}
if (t == 2) {
return;
}
if (t == 3) {
return;
}
set();
}