Programming
Programming
• General if statement
• If --------- else statement
• Else if chain and nested loop
What is if statement?
The if statement either selects an action, if a condition is
true or skips the action if the condition is false.
if(a>b)
printf("a is more than b \n");
return 0;
}
Output
a is less than b
It allows you to specify that
If else different actions are to be
statement performed when the condition is
true and when it’s false.
Flow chart
if(expression){
Statement_1;
else
Statement_2;
Input Output
If (expression)
Statement_1;
else if (expression)
statement_2;
else if (expression)
statement_2;
-
-
else if (expression)
statement_2;
else
statement_x;
A switch statement is a type of selection control
Switch mechanism used to allow the value of a variable or
expression to change the control flow of program
statement execution via a multiway branch.
Keyword
1)Switch
2)Case
3)Break
4)Default
Flow diagram
Limitations of switch over if-else ladder
3.It is more manageable for having higher level of indentation than if.