I am new to C++. I often see conditional statement like below:
if
statement_0;
else if
statement_1;
Question:
Syntacticall
Syntactically, it's not a single keyword; keywords cannot
contain white space. Logically, when writing lists of else
if
, it's probably better if you see it as a single keyword,
and write:
if ( c1 ) {
// ...
} else if ( c2 ) {
// ...
} else if ( c3 ) {
// ...
} else if ( c4 ) {
// ...
} // ...
The compiler literally sees this as:
if ( c1 ) {
// ...
} else {
if ( c2 ) {
// ...
} else {
if ( c3 ) {
// ...
} else {
if ( c4 ) {
// ...
} // ...
}
}
}
but both forms come out to the same thing, and the first is far more readable.