If-else Ladder in C
Useful for if-else kind of conditional execution when we have more than two related conditional statements.
Syntax :
if(boolean_expression 1) { /* Executes when the boolean expression 1 is true */ }else if( boolean_expression 2) { /* Executes when the boolean expression 2 is true */ }else if( boolean_expression 3) { /* Executes when the boolean expression 3 is true */ } else { /* executes when the none of the above condition is true. */ }
Block Diagram :

Example:
WAP to give choice to user from menu to perform action.#includeOUTPUT:int main(){ int x ; printf("MENU\n----------"); printf("\n1. for Hello"); printf("\n2. for Bye"); printf("\n-----------"); printf("\nEnter Your Choice: "); scanf("%d",&x); if(x==1) { printf("HELLO USER!!"); } else if(x==2) { printf("BYE USER!!"); } else { printf("INVALID CHOICE"); } }
MENU ----------- 1. for Hello 2. for Bye ----------- Enter Your Choice: 3 INVALID CHOICE
Next topic is nested if statement in C
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at info@prowessapps.in
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at info@prowessapps.in