Table of Contents
break statement in C
Using break statement we can get out of loop when certain condition is matched.
In C program break statement is used in 2 ways.
- To get out of loop when given condition is matched
- It is also used in switch case to get out of case, and preventing next from execution.

Example of break statement with while loop
#include<stdio.h>
void main()
{
int i=0;
while(i<=5)
{
i++;
if(i == 3)
{
break;
}
printf("%d ITVoyagers n",i);
}
}
Output:
1 ITVoyagers
2 ITVoyagers
In above example while loop will starting iterating because initial condition is valid and it will print value of i followed by ITVoyagers, but when value of i reaches to 3 then condition for inner if statement gets true and this will execute break statement, which will force while loop to stop iterations and get out of loop, hence loop execution stops after “2 ITVoyagers”.
Example of break statement with do-while loop
#include<stdio.h>
void main()
{
int i=0;
do
{
i++;
if(i == 3)
{
break;
}while(i<=5);
printf("%d ITVoyagers n",i);
}
}
Output:
1 ITVoyagers
2 ITVoyagers
Example of break statement with for loop
#include<stdio.h>
void main()
{
int i;
for(i=0; i<=5; i++)
{
if(i == 3)
{
break;
}
printf("%d ITVoyagers n",i);
}
}
Output:
0 ITVoyagers
1 ITVoyagers
2 ITVoyagers
Example of break statement with switch case
#include<stdio.h>
void main()
{
int i=1;
switch(i)
{
case 0:
printf("%d ITVoyagers",i);
break;
case 1:
printf("%d ITVoyagers",i);
break;
case 2:
printf("%d ITVoyagers",i);
break;
default:
printf("%d ITVoyagers",i);
break;
}
}
Output:
1 ITVoyagers
Try this practice quiz
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
PRACTICALS IN C PROGRAM
Programs to understand the basic data types and I/O.
Programs on Operators and Expressions.
Programs on decision statements.
Programs on looping.
Programs to understand the basic data types and I/O.
Programs on arrays.
Programs on functions.
Programs on structures and unions.
Programs on pointers.
Programs on string manipulations.
