Else – If Ladder

In C programming language the else if ladder is a way of putting multiple ifs together when multipath decisions are involved. It is a one of the types of decision making and branching statements. A multipath decision is a chain of if’s in which the statement associated with each else is an if. The general form of else if ladder is as follows –

if ( condition 1)
        statement - 1;
        else if (condtion 2)
                statement - 2;
                else if ( condition n)
                        statement - n;
                                default statment;

This construct is known as the else if ladder.The conditions are evaluated from the top of the ladder to downwards. As soon as a true condition is found, the statement associated with it is executed and the control is transferred to the statement-x (skipping the rest of the ladder). When all the n conditions become false, then the final esle containing the default statement will be executed.

Below is the sample C program of the if – else ladder statement in which the color is to be selected by using the if – else ladder –

void main()
     int n;
     printf(" Enter 1 to 4 to select random color");
             printf("You selected Red color");
          else if(n==2)
               printf("You selected Green color");
               else if(n==3)
                    printf("You selected yellow color");
                    else if(n==4)
                         printf("You selected Blue color");
                             printf("No color selected");

Note – C programming language is a structured language; so it will be better to form blocks in ‘if else ladder’ as this makes the programmer to understand the language better and reduces the confusion and chaos. Also it will make the others easy to understand your program. It is also necessary to align the opening and the closing braces of the block.


  1. IT Training says:

    Very nice tutorial

  2. gokul says:

    i got one error.what can i do…

  3. mahmud says:

    nice program

  4. it training says:

    i got one 2 errors….. number 4 and 30

  5. shalu says:

    write a program to enter total sales you will calculate discount as per given condition.
    sales discount
    2000 && 40000 && 60000 && 80000 10%
    you will print total sales ,discount amount, pay bill amount.

    • Sherlyn says:

      Most help articles on the web are inaccurate or inhrteoenc. Not this!

    • join car insuarance says:

      We could’ve done with that insight early on.

  6. Subhasis Sarkar says:

    Nice tutorial.

  7. rundy says:

    humko chodo pls.

  8. sripriya says:

    i want more information about c programing

  9. dheetchitha says:

    i want more examples on else if ladder with output

  10. hitesh says:

    write a program to change c’s background

    please try it

  11. Suji says:

    I want an another else if prgm with output

    • Marge says:

      A plngsiealy rational answer. Good to hear from you.

  12. ekramulla says:

    hi please send number of programs in if and if else and if ladder and nested program in my mail id

  13. dfgf says:


Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This