Recently, I encountered some condition judgment statements in my work. The scenario is as follows:
1. The aggregation statistics method entered by the user can only be used in two cases: max (...) and min (...)
2. The input interpretation module truncates the first four characters and then compares and matches them as strsummaryway.
I can see that this process is as follows:
If (summaryway = 'max (')
Processing Based on the maximum value;
Else
Processing Based on the minimum value;
Obviously, this is an incomplete expression of judgment. if the input is not considered, it may be a case other than Max and Min, but it is assumed that Max is Min. the modified processing method should be:
If (strsummaryway = 'max (')
Processing Based on the maximum value;
Else if (strsummaryway = 'min (')
Processing Based on the minimum value;
Else
Returns an error or throws an exception (as required by the Program );
From this simple method, I am also alert myself,
1. Complete judgment and processing should be considered.
2. Determine the IF-else condition and use the last else to handle exceptions.
3. If there is a 1% Probability Error in a function, it will be executed 10 times, and 20 times it is similar to a 1% probability error function, the probability of an error is quite high!