General Control Issues

xiaoxiao2021-03-06  96

Boolean Expressions1. Break complicated tests into partial tests with new boolean variables.Rather than creating a monstrous test with half a dozen terms, assign intermediate values ​​to terms that allow you to perform a simpler test.2. Move complicated expressions into boolean functionsIf a test is repeated often or distracts from the main flow of the program, move the code for the test into a function and test value of the function.3. Use decision tables to replace complicated conditionsSometimes you ahve a complicated test involving serveral variables. It can be helpful to use a decision table to perform the test rather than using ifs or cases.4. in if statements, convert negatives to positives and flip-flop the code in the if and else clauses.5. Apply DeMorgan's theorems to simplify boolean tests with Negatives.if (! Displayok ||! Printerok) IF (! (! (! (! "

Compound Statements (Blocks) 1. Write Pairs of Braces Together2. Use Braces To Clarify Conditions.

Taming Dangerously Deep NestingMany researchers recommend avoiding nesting to more than three or four levels.1. Simplify a nested if by retesting part of the condition.2. Simplify a nested if by using a break block.3. Convert a nested if to a set OF IF-THEN-ELSES4. Convery a Nested if to a Case Statement5. Factor Deeply Nested Code ITO ITS OWN Routine.

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

New Post(0)