if (boolExpr1)
if (boolExpr2)
if (boolExpr3) {
stml1;
}
else {
Stml2;
}
else {
Stml3;
}
This code is very confusing!
Please note that there is no else part for the first if construct.
The
compiler associates the else part with the closest inner
if
construct which does not have an else part.
Thus, each else part is associated with the respective
if.
To avoid this confusion, it is better to use
braces appropriately for the association of each
else
part with its
if.
By using the braces, any
else
Do'stlaringiz bilan baham: