C++ If-else-if
C++ if.. else if Control Statement
if.. else if control statement is an if statement used with an optional else if control statement to check multiple conditions. In this control statement, when any one of condition returns true, then none of the other else if or else will be executed.Syntax
Output:
if(check_condation){
statement;
}
else if(check_condation){
statement;
}
else{
statement;
}
C++ if..else if Example
#include <iostream>
using namespace std;
int main()
{
int a=10;
int b=20;
if(a<b)
{
cout << "a is less than b"<<endl;
}else if(b<a){
cout << "b is less than a"<<endl;
}
else
{
cout << "Both are equal"<<endl;
}
cout<< "value of a is :"<< a<<" value of b is :"<<b;
return 0;
}
a is less than b: value of a is: 10 value of b is: 20