C programming tutorial

                  PREVIOUS                                                                                   NEXT CHAPTER

Nested If Statement in C

 

Nested if statement in C is an if that has another if statement in its if body or in its else body.

I will explain it using following C program.

int i=2;

if(i<2)
{
printf(" nested if c");
}
else {
if( i>2)
printf("i am learning c");
else
printf(" NESTED IF C");
}

  1. In above program i was initialized to 2 in first step.
  2. condition inside if evaluates to false since i is not less then two.therefore statements inside if will not execute.control will go to else part.
  3. Inside else there is another if else.Condition inside if evaluates to false since i is not greater then two.therefore statements inside if will not execute .Control will go to else part..
  4. Hence output will be NESTED IF C.

 



                  PREVIOUS                                                                                   NEXT CHAPTER