Control Statements:
In previous programs, statements are executed sequentially. They are some situations, statements are executed with conditions in such cases we can use control statements. These statements are also called decision making statements. It is used perform the decision when writing program. When taken condition if it is “true” or “false”, based on that statements are executed.
C language supports Four types of Control statements.
I. if statement.
II. switch Statement.
III. conditional Operator statement.
IV. goto Statement.
I. IF statement:
In all control statements, if statement is most powerful decision making statement. It is a two-way decision statement. The general form of if statement is as follows.
Syntax:
if ( condition )
{
statement 1;
statement 2;
….
}
statement x;

When execute the if condition whether it is “true” or “false”. Based on the condition statements are divide into three types.
- if….else statement.
2.else if statement.
3.nested if statements.
1.if…else statement: This is most common used statement perform the single condition in your program statements. The general syntax of if…else statement is:
Syntax:
if ( condition)
{
st1;
st2;
}
else
{
st3;
st4;
}
st-x;

Whenever execute the if…else statement first check the condition. if the condition is “true” then if block of statements will be executed. If condition is “false ” then else block statement will executed. In both cases statement-x will be executed.
Here some examples are given to demonstrate if…else statement.
- WAP enter two numbers equal or not?
- WAP enter number whether it is even or odd number?
- WAP enter character whether it is letter or not?
- WAP enter five subjects marks whether pass or fail?
- WAP enter year leap year or not ?
else if statement: This statement is used for check the more than one condition in your program statements. when execute the else if statement, first check condition 1. if it true then execute the first statement. other wise check the condition 2, if it is false, check the condition 3…… and so. if does not perform any condition last else will be executed. It is also known as else if ladder. The general syntax of else if statement is:
syntax:
if(condition 1)
statement 1;
else if(condition 2)
statement 2;
else if(condition 3)
statement 3;
else if(condition 4)
statement 4;
else
statement 5;

Here some examples are given to demonstrate else if statement.
- Write a C program to find the roots of a quadratic equation.
Nested if statements: This statement is used for put a if statement inside another if statement. When the outer if statement is true then only inner if statement is executed. If outer if statement is false it is can’t possible to execute inner if statement. The general syntax of nested if statement is:
syntax:
if(condition1)
{
if(condition)
statement 1;
else
statement 2;
}
else
statement 3;
statement x;

Here some examples are given to demonstrate Nested if statement.
- Write a C Program to find Biggest among three numbers.
Note : It is possible if statement without using else statement as per user requirement in all above three types.
II. switch statement:
This is another control statement supported C language. It is used for check unconditional statements. The switch takes variable value, if the value matches any case label, that case will be executed. Every case statement followed by value and colon. It ends with break keyword. If the value does not match any case label default case will be executed. The general syntax of switch statement is as follows.
Syntax:
switch(variable)
{
case val:
Statements-1
break;
case val:
Statements-2
break;
case val:
Statements-3
break;
default:
Statements-4
}
Statements-X

Here some examples are given to demonstrate switch statement.
- Write a C program, which takes two integer operands and one operator form the user, performs the operation and then prints the result. (Consider the operators +,-,*, /, % and use Switch Statement)
- Write a C Program to convert decimal to binary and hex (using switch call function the function)
Note: In Switch statement every case must be ended with break, otherwise it results run time errors.
III. Conditional Operator:
This is combination of “? and :”. it is used to check the small conditions in your program statements.When execute the condition operator first check the conditional expression. It gives either “true” or “false”, If it is true then check the expr1, otherwise check the expr2. The general syntax of this statement is:
Syntax:
conditionalexpr ? expr1 : expr2 ;
Here some examples are given to demonstrate switch statement.
- Write a C Program to demonstrate Conditional operator.
IV. goto statement:
This is an unconditional statement. Generally it used to execute the program repeatedly until user press ctrl+break key. What ever process continuously we can put into the goto block. The general syntax of goto statetment is:
Syntax:
label:
statement1;
statement2;
goto label;
ex:
hai:
printf(“Welcome”);
goto hai;
Click Here for practicing list.