Types of Control Statements in C
Types of Control Statements in C
Types of Control Statements in C
In C, the control flows from one instruction to the next instruction until now in all
programs. This control flow from one command to the next is called sequential
control flow. Nonetheless, in most C programs the programmer may want to skip
instructions or repeat a set of instructions repeatedly when writing logic. This can be
referred to as sequential control flow. The declarations in C let programmers make
such decisions which are called decision-making or control declarations.
Decision statement
Decision statement is condition based statement. It define single or set of conditions that
must be satisfied before statement/s can execute. For example, allow amount
withdrawal from ATM, only if pin validation succeeds. These situations are handled
using decision statements.
1. Simple if statement
2. if...else
3. if...else...if statement
4. Nested if...else statement
5. Switch...case
Looping statement
In programming, there exists situations when you need to repeat single or a group of
statements till some condition is met. Such as - read all files of a directory.
Looping statements are also known as iterative or repetitive statement.
1. for loop
2. while loop
3. do...while loop
Jump statements
1. break
2. continue
3. goto
The goto statement is known as jump statement in C. As the name suggests, goto is
used to transfer the program control to a predefined label. The goto statment can be
used to repeat some part of the code for a particular condition. It can also be used to
break the multiple loops which can't be done by using a single break statement.
However, using goto is avoided these days since it makes the program less readable
and complecated.
Syntax
goto label;
..
label: statement;
Here label can be any plain text except C keyword and it can be set anywhere in the
C program above or below to goto statement.
Flow Diagram
Example
#include <stdio.h>
int main () {
int a = 10;
/* do loop execution */
LOOP:do {
if( a == 15) {
a = a + 1;
goto LOOP;
a++;
}while( a < 20 );
return 0;