C Language Selection Statements if()...else Ladder Chaining two or more if () ... else statements

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

While the if ()... else statement allows to define only one (default) behaviour which occurs when the condition within the if () is not met, chaining two or more if () ... else statements allow to define a couple more behaviours before going to the last else branch acting as a "default", if any.

Example:

int a = ... /* initialise to some value. */

if (a >= 1) 
{
    printf("a is greater than or equals 1.\n");
} 
else if (a == 0) //we already know that a is smaller than 1
{
    printf("a equals 0.\n");
}
else /* a is smaller than 1 and not equals 0, hence: */
{ 
    printf("a is negative.\n");
}


Got any C Language Question?