Break and Continue Statements in C Programming
Break and Continue Statements in C Programming
Introduction to Break and Continue Statements
Break and continue statements in C programming are used to control the flow of loops. They help you stop a loop early or skip specific iterations based on conditions.
Break and continue statements in C programming are commonly used with for loop, while loop, and do while loop to make programs more efficient and readable.
Break Statement in C Programming
What is Break Statement
The break statement is used to immediately exit a loop or switch statement when a condition is satisfied.
Syntax of Break Statement
Example 1: Break in For Loop
int main() {
int i;
for(i = 1; i <= 10; i++) {
if(i == 5) {
break;
}
printf(“%d\n”, i);
}
return 0;
}
Example 2: Break in While Loop
int main() {
int i = 1;
while(i <= 10) {
if(i == 6) {
break;
}
printf(“%d\n”, i);
i++;
}
return 0;
}
Example 3: Break in Switch Case
int main() {
int choice = 2;
switch(choice) {
case 1:
printf(“Option 1”);
break;
case 2:
printf(“Option 2”);
break;
default:
printf(“Invalid choice”);
}
return 0;
}
Continue Statement in C Programming
What is Continue Statement
The continue statement is used to skip the current iteration and move to the next iteration of the loop.
Syntax of Continue Statement
Example 1: Continue in For Loop
int main() {
int i;
for(i = 1; i <= 5; i++) {
if(i == 3) {
continue;
}
printf(“%d\n”, i);
}
return 0;
}
Example 2: Continue in While Loop
int main() {
int i = 0;
while(i < 5) {
i++;
if(i == 2) {
continue;
}
printf(“%d\n”, i);
}
return 0;
}
Combined Example of Break and Continue
int main() {
int i;
for(i = 1; i <= 10; i++) {
if(i == 3) continue;
if(i == 8) break;
printf(“%d\n”, i);
}
return 0;
}
Key Differences Between Break and Continue
Break Statement
- Exits the loop immediately
- Stops further execution
Continue Statement
- Skips current iteration
- Continues with next iteration
When to Use Break and Continue
Use Break When
- You want to stop the loop early
- A condition is fully satisfied
- Working with switch statements
Use Continue When
- You want to skip specific values
- Filtering data in loops
- Avoid unnecessary execution
Advantages of Break and Continue Statements
Key Benefits
- Better control over loops
- Improves program efficiency
- Reduces unnecessary execution
- Makes code clean and readable
Start Learning C Programming
Practice break and continue statements with different loops to improve your programming logic.
Summary
Break and continue statements in C programming are used to control loop execution. Break exits the loop completely, while continue skips the current iteration and continues execution.
FAQs
What is break statement in C programming?
Break is used to exit a loop or switch immediately.
What is continue statement in C programming?
Continue skips the current iteration and moves to the next.
Can we use break in all loops?
Yes, break can be used in for, while, and do while loops.
What is the main difference between break and continue?
Break stops the loop, while continue skips one iteration.



