Control Statements in C Gate Notes 72
Control Statements in C Gate Notes 72
Control Statements in C Gate Notes 72
The “if” statement is the simplest decision control statement frequently used to
transfer the flow of control from one part to the other part of the code. The if block
may include one statement or n statements enclosed within curly brackets.
Example of a C program with an if statement:
#include< stdio.h>
int main()
int a=10;
if(a>0)
a++;
printf(“%d”, a);
return 0;
Output: 11
In the if-else construct, first, the test expression is evaluated. If the expression is
true, then if the block is executed otherwise, the else block is executed. The if-else
construct is different from that of the if statement. An example of an if-else block is
as follows:
#include< stdio.h>
int main()
int a=10;
if(a%2==0)
printf(“%d”, a is even);
else
printf(“%d”, a is odd);
return 0;
Output: a is even
The “if-else-if” Statement
In the ”if-else-if” construct, first, the test expression is evaluated. If the expression is
true, then if the block is executed otherwise, the else block is executed; it supports
an additional condition apart from the initial test condition. The “if-else-if” construct
works similarly to a normal if statement.
Example:
#include< stdio.h>
int main()
int number;
scanf(“%d”, &number);
if(number==0)
else if(number>0)
else
return 0;
Switch Case
switch(variable)
{
case value 1:
statement block 1;
break;
case value 2:
statement block 2;
break;
case value N:
statement block N;
break;
default:
statement block D;
break;
Statement X;
Iterative Statements in C
The iterative statements are used to repeat the execution of a particular sequence of
instructions until the specified expression becomes false. The C language supports
three types of iterative statements also known as looping statements. The iterative
statements present in C are as follows:
Jump Statements in C
To transfer the control from one block to another, we use jump statements; for
transferring control, we have two types of jump statements: broken and continuous.
The jump statements are also used in questions asked in the GATE exam. In C
programming language, the break statement is used to terminate the execution of
the nearest enclosing loop in which it appears.
The break statement is widely used in decision control statements and iterative
statements. It is frequently used in switch cases and iterative statements like for,
while, and do-while.