Nested if-else

Default Image

C++ allows us to use if-else statement in a
nested form. Nested form is to use another if statement in an if
statement. The if statement that contains another if statement is called
outer if statement. The if statement that is inside outer if is called
inner if statement. The control enters the inner if structure only when
the condition of outer if statement is true.

Nested if statement is used when multiple
conditions must check. Nesting can be applied at any level, but it
increases the complexity of logic of the programme.


nested-if-else


Let’s explain this with an example:


#include

#include

void main()

{

clrscr();

int a;

cout<<"Enter a value "; cin>>a;

if (a>=10)

{

if (a>=15)

{

cout<
}

else

{

cout<
}

}

else

{

cout<
}

getch();

}


To get nested if-else source code you can click here.


 

Read Count: 3 times

Comments

No comments yet.

Leave a Comment