
5.3 Selection Using if/else 223
Note that we could have used two sequential if statements, as in:
if ( grade >= 60 )
message = “You passed”;
if ( grade < 60 )
message = “You failed “;
However, if the first condition, (grade >= 60), is false, the second condition,
(grade < 60), must be true. So an if/else simplifies our processing and avoids
unnecessarily testing two conditions when only one of the conditions can
be true.
Block Scope
The scope of a variable is the region within a program where the variable
can be referenced, or used. When we declare a variable, its scope extends
from the point at which it is declared until the end of the block in which we ...