# Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

## if-else-if Statement OR else if Ladder :

Suppose we need to specify multiple conditions then we need to use multiple if statements like this –

```void main ( )
{
int num = 10 ;

if ( num  >  0 )
printf ("
Number is Positive");

if ( num  <  0 )
printf ("
Number is Negative");

if ( num  ==  0 )
printf ("
Number is Zero");
}
```

which is not a right or feasible way to write program. Instead of this above syntax we use if-else-if statement.

### Consider the Following Program –

```void main ( )
{
int num = 10 ;
if ( num  >  0 )
printf ("
Number is Positive");
else if ( num  <  0 )
printf ("
Number is Negative");
else
printf ("
Number is Zero");
}
```

## Explanation :

In the above program firstly condition is tested i.e number is checked with zero. If it is greater than zero then only first if statement will be executed and after the execution of if statement control will be outside the complete if-else statement.

```else if ( num  <  0 )
printf ("
Number is Negative");
```

Suppose in first if condition is false then the second condition will be tested i.e if number is not positive then and then only it is tested for the negative.

```else
printf ("
Number is Zero");
```

and if number is neither positive nor negative then it will be considered as zero.

## Which is faster and feasible way for Writing If ?

Point Example 1 Example 2
No of If Statements 3 2
No of times Condition Tested (Positive No.) 3 1
No of times Condition Tested (Negative No.) 3 2
No of times Condition Tested (Zero No.) 3 2

## Flowchart for If-Else Ladder : 