if else if ladder statement in c language
It is basically a multi way decision making statement. In if else if ladder statement, there are multiple conditions one after another. Depending upon these conditions, specific sets of statements are executed.
The syntax of if else if ladder statement is:
else if (Condition-3)
Initially Condition-1 is checked. If it is true, Statement-Block-1 will be executed. If Condition-1 is false, Condition-2 will be checked. If Condition-2 is true Statement-Block2 will be executed. If Condition-2 is false, Condition-3 will be checked.
Statement-Block-N will be executed if all conditions are false.
|Program to demonstrate the use of if else if ladder statement.|
printf(“\nEnter a value :=”);
printf(“\nValue is positive”);
printf(“\nValue is negative”);
printf(“\nValue is zero”);
|Enter a value :=6|
Value is positive
In the above program, a has been entered 6. Condition if(a>0) is true, printf(“\nValue is positive”) would be executed.