Java Reference
In-Depth Information
ates to false and the second one never takes place. We have used indenta-
tion to indicate that the second if statement is subordinate to the first
one. Although white space has no effect on the code, text line indentation
doeshelpvisualizelogicalflow. Figure9-1 isaflowchartofanestedif
construct.
START
is user input
equal to 1 OR 2
?
NO
YES
Message:
“BEEP-BEEP”
nested if
is user input
equal to 1
?
Message:
“Input = 1”
YES
NO
END
Figure 9-1 Flowchart of a Nested if Construct
The else construct
An if construct executes a statement, or a statement block, if the condi-
tional clause evaluates to true, but no alternative action is taken if the ex-
pression is false. The if-else construct allows Java code to provide an
alternative processing option for the case where the conditional clause is
false.
Programmers note:
The else construct is sometimes called the if-else construct.
 
Search WWH ::




Custom Search