6, if statement handles the error

xiaoxiao2021-03-06  86

I saw you said, what is good to say. Still first look at a program code.

IF (ch> = '0' && ch <= '9') {

/ * Normal processing code * /

} else {

/ * Output error message * /

Printf ("Error ... / N");

Return (False);

}

This structure is very bad, especially if "normal processing code" is long, it is best not to use ELSE for this situation. Judgment the error first, such as:

IF (CH <'0' || CH> '9') {

/ * Output error message * /

Printf ("Error ... / N");

Return (False);

}

/ * Normal processing code * /

......

Is this structure not very clear? Highlight the wrong condition, let others use your function, you can see unhanectation conditions, so you will be more conscious.

转载请注明原文地址:https://www.9cbs.com/read-107746.html

New Post(0)