ECMA-334 C# Language Specification15.7.1: The if statement |
The if statement selects a statement for execution based on the value of a boolean expression.
(
boolean-expression
)
embedded-statement
(
boolean-expression
)
embedded-statement
else embedded-statement
expression
An else part is associated with the lexically nearest preceding if that is allowed by the syntax.
is equivalent to
if (x) if (y) F(); else G();
end example]
if (x) {
if (y) {
F();
}
else {
G();
}
}
An if statement is executed as follows:
boolean-expression
(14.16) is evaluated. The first embedded statement of an if statement is reachable if the if statement is reachable and the boolean expression does not have the constant value false.
The second embedded statement of an if statement, if present, is reachable if the if statement is reachable and the boolean expression does not have the constant value true.
The end point of an if statement is reachable if the end point of at least one of its embedded statements is reachable. In addition, the end point of an if statement with no else part is reachable if the if statement is reachable and the boolean expression does not have the constant value true.