Nested if statement
- The if block may be nested in another if or else block. This is called nesting of if or else block.
if(condition 1)
{
if(condition 2)
{
statement(s);
}
}
if(condition 1)
statement 1;
else if (condition 2)
statement2;
else
statement3;
if-else-if example |
if(percentage>=60) |
For Example
#include <iostream>
using namespace std;
int main ()
{
int marks = 55;
if( marks >= 80) {
cout << "U are 1st class !!";
}
else {
if( marks >= 60) {
cout << "U are 2nd class !!";
}
else {
if( marks >= 40) {
cout << "U are 3rd class !!";
}
else {
cout << "U are fail !!";
}
}
}
return 0;
}
Output :
U are 3rd class !!