Control Statements in C Language
In general, control statements in C are used to execute/transfer the control. It helps to control the order in which the statements to be execute. In a procedural language, the program's flow is usually from top to bottom (means Sequential flow). But in most C programs the programmer may want to execute a particular set of instructions when it fulfills a specific condition or wants to run a set of instructions for a specified number of times. This can be referred as sequential control flow statement. The various types of control statements in C language are as under:-
- Sequential
- Conditional
- Iteration
Sequential control
In sequential control, the C program statements are executed sequentially i.e., one after the another from beginning to end.
Statement 1 |
⤋ |
Statement 2 |
⤋ |
Statement 3 |
#include<stdio.h> void main() { int x , y, sum; printf("Enter the two numbers"); scanf("%d%d",&x,&y); sum=x+y; printf("Sum=%d",sum); }
Conditional Control (Decision Control)
In conditional control, the execution of statements depends on the condition. If the condition is true, then a set of statements is executed otherwise other set of statements is followed. This control is also called Decision Control because it helps in making decision about which set of statements is to be executed. Decision control structure in C can be implemented by using -
- If statement
- If-else statement
- Nested if else statement
- else-if ladder
- case control structure
- conditional operator
Iteration Control ( Loops )
Iterations or loops are used when programmer want to execute a statement or block of statements repetedly. The repetition of loops is controlled with the help of a condition. The statements in the loop keep on executing repetedly until the condition becomes false. There are the following three types of loops:-
- While loop
- Do-while loop
- For loop