I am new to C++. I often see conditional statement like below:
if
statement_0;
else if
statement_1;
Question:
Syntacticall
An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.
When using if , else if , else statements there are few points to keep in mind.
An if can have zero or one else's and it must come after any else if's.
An if can have zero to many else if's and they must come before the else.
Once an else if succeeds, none of he remaining else if's or else's will be tested.
have a look if...else statement tutorial.
You can see the scope by using curly braces:
if(X) {
statement_0;
}
else {
if(Y) {
statement_1;
}
}
And normally implemented with two distinct keywords, one is if and one is else.