Also, the IF-else statement

Source: Internet
Author: User

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!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.