8
Statements
[stmt.stmt]
8.5
Selection statements
[stmt.select]
8.5.1
General
[stmt.select.general]
1
#
Selection statements choose one of several flows of control
.
selection-statement
:
if
constexpr
o
p
t
(
init-statement
o
p
t
condition
)
statement
if
constexpr
o
p
t
(
init-statement
o
p
t
condition
)
statement
else
statement
switch
(
init-statement
o
p
t
condition
)
statement
See
[dcl.
meaning]
for the optional
attribute-specifier-seq
in a condition
.
[
Note
1
:
An
init-statement
ends with a semicolon
.
—
end note
]
2
#
The substatement in a
selection-statement
(each substatement, in the
else
form of the
if
statement) implicitly defines a block scope (
[basic.
scope]
)
.
If the substatement in a
selection-statement
is a single statement and not a
compound-statement
, it is as if it was rewritten to be a
compound-statement
containing the original substatement
.
[
Example
1
:
if
(
x
)
int
i;
can be equivalently rewritten as
if
(
x
)
{
int
i;
}
Thus after the
if
statement,
i
is no longer in scope
.
—
end example
]