Control-conditionals

xiaoxiao2021-03-06  76

. Guidelines when writing if statements1 Write the nominal path through the code first;. Then write the unusual cases.2 Make sure that you branch correctly on equality.3 Follow the if clause with a meaningful statement.4 Conside the else clause... 5. Test the else clause for correctness.6. Check for revseal of the if and else clauses.7. Simplify complicated tests with boolean function calls.8. Put the most common cases first.9. Make sure that all cases are covered. 10. REPLACE IF-THEN-ELSE CHAINS with other constructs if your language supports them.

Case statement1. Order casesalphabetically or numerically if they are equally important.2. Put the normal case first.3. Order cases by frequency.4. Keep the actions of each case simple.5. Do not make up phony variables in order to be able to use the case statment.6. use the default clause only to detect legitimate defaults.7. use the default clause to detect errors.8. In C and Java, avoid dropping through the end of a case statement.

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

New Post(0)