|
|
|
|
|
|
|
Figure 5-6
Flow of Control for Module Print Activity |
|
|
|
|
|
|
|
|
In this problem, the nested If version of the solution has four relational operators; the other solution had eight. Because it uses fewer operations to accomplish the same task, the nested Ifs are more efficient. |
|
|
|
|
|
|
|
|
Notice the indentation we use for the nested If statements. When a deeply nested selection structure represents a series of alternate choices, in which each choice depends on the previous one being FALSE, we format the code as a series of branches. Each of the nested If statements begins with else if. The else indicates that the if is executed only if the preceding conditions are FALSE. Besides making the code look more like a series of If statements, this style avoids deep indentations that leave no room for writing a statement. |
|
|
|
|
|