use of "else if" in c++

No, in the first case you execute the else block only if the <condition-statement> is not verified AND only if <condition-statement-2> is verified.

In the second case you execute the else block simply if the <codition-statement> is not verified.

In this case are equivalent until you does not have any //statements-2.

About the question : when is the else if (in c++) used ?

Is used basically under the same conditions of all other languages​​ that have this construct. else is executed as alternative to the related if, else-if is executed as alternative but with an 'attached' if to be verified, otherwise is not executed. So they are not logically equivalent.


the syntax of an if is really

if(condition) statement;

What the {} really do is allow you to group together multiple statements. In your second example you only have one statement(the if) inside your {}s, so yes, both examples are the same, except //statements-2 always gets run when !=true


The only difference is in example 1 your Statement2 will get executed regardless of the conditions you check. In example 2, Statement2 will only get executed if your if condition is false. Other than that, they're basically the same.