C++ Nested if
C++ nested if Control Statement
Nested if control statement refers to if condition within if condition. C++ compiler checks nested if control statement when its parent if condition returns true, then the program is executed according to nested if condition.Syntax
Output
if(check_condation){
statement 1;
...;
if(check_condation){
statement I;
...
}
...;
}
Example
#include <iostream>
using namespace std;
int main () {
int a=10;
int b=20;
if( a < b ) {
cout << "a is less than b:" << endl;
if(b>a){
cout<<"b is greater than a:"<<endl;
}
}
cout<<"value of a is: "<<a <<" value of b is: "<<b;
return 0;
}
a is less than b: b is greater than a: value of a is: 10 value of b is: 20