Difference Between Break and Continue Statements in C

By Anjnee Bhatnagar|Updated : September 27th, 2022

The Difference Between Break and Continue Statements in C is that break is used to end the loop immediately. 'Continue,' on the other hand, ends the current iteration and returns control to the loop's next iteration. Both break and continue statements alter the flow of execution in a program. These keywords are used in control statements in C programs.

In this article, we will learn about the difference between break and continue statements based on 4 different factors, and after that, we will understand the use of each keyword in the programs.

Download Complete Operating System Formula Notes PDF

Difference Between Break and Continue Statement

One of the primary reasons to pause a loop early is with the Break keyword. But the Continue statement can also interrupt a loop, though in a way that's quite different from Break. The difference between break and continue statements are as follows:

Key Differences Between Break and Continue Statement

Break

Continue

The break statement is used to exit from the loop.

The continue statement is not used to exit from the loop.

The break statement results in the control transfer out of the loop where the break keyword appears.

Continue statement results in skipping the loop's current iteration and continuing from the next iteration.

It results in the loop's early termination.

The continue statement causes the next iteration to start earlier.

The 'break' command terminates the loop.

'continue' does not stop the loop from continuing, merely the current iteration.

Syntax: break;

Syntax: continue;

Break and Continue Statement

Various one-token statements are used in a program to break or halt the control flow. Two important one-token statements are:

  • Break Statement
  • Continue Statement

What is a Break Statement?

The “break” keyword is used to terminate the execution of the current loop in which it is used. The break keyword is most widely used in control statements of C language, such as with for loop, while loop, do-while loop, and switch statements. Whenever the compiler encounters a break statement, the control is transferred to the statement that follows the loop in which the break statement is present.

Difference between Break and Continue Statement PDF

The syntax of the break statement is as follows: break; (The keyword “break” followed by a semicolon.)

Example of Break Statement

#include <stdio.h>

int main()

{

int a=0;

while(a<=10)

{

if(a==5)

break;

printf(“%d”, a);

a=a+1;

}

return 0;

}

Output: 0 1 2 3 4

As it can be seen from the above example that as soon as the value of a becomes equal to 5, the break statement is executed, and the control jumps out of the loop, bypassing its normal termination expression.

What is a Continue Statement?

Like the break statement, the continue statement can only appear in the loop's body. Whenever the compiler encounters a continue statement, then the rest of the statements of the loop are skipped, and the control is transferred to the nearest loop continuation portion of the enclosing loop. The keyword “continue” is also frequently used in control statements like for loop, while loop, and do-while loop. The syntax of the continue statement is as follows: continue; (The keyword “continue” followed by a semicolon.)

Example of Continue Statement

#include <stdio.h>

int main()

{

int a;

for(a=0; a<=10; a++)

{

if(a==5)

continue;

printf(“%d”, a);

}

return 0;

}

Output: 0 1 2 3 4 6 7 8 9 10

As soon as a becomes equal to 5, the continue statement is encountered, so the printf statement is skipped, and the compiler executes the next iteration.

Check out some important topics related to the difference between break and continue statements in the table provided below:

Related GATE Notes
Difference Between POP and OOPDifference Between List and Tuple in Python
Difference Between Unique and primary keyDifference Between Calloc () and Malloc ()
Difference Between Mealy machine and Moore machineDifference Between High-Level and Low-Level Languages

Comments

write a comment

FAQs on Difference Between Break and Continue Statements in C

  • The main difference between the break and continue statements in C is that the break statement causes the innermost switch or enclosing loop to terminate immediately. The continue statement, on the other hand, starts the next iteration of the while, for, or do loop.

  • Based on the loop construct the difference between break and continue statements is that the break statement allows a user to quit a loop structure whereas, the continue statement does not allow a user to quit an overall loop structure.

  • The control statements enable programmers to conditionally execute a particular block of code. There are three types of control statements in C: Branch or decision making, Iterative or looping, and jump statements.

  • The decision control statements can alter the path of execution of the program. The decision control statements allow jumping from one part of the program to another. These are of four types, which are as follows: if statements, if-else statements, if-else-if statements, and the switch case statements.

  • The iterative statements are used to repeat the execution of a sequence of statements until the expression becomes false. The C language supports three types of looping or iterative statements which are as follows: for loop, while loop, and do-while loop.

  • Based on the tasks, the difference between break and continue statements is that break terminates the execution of the remaining iteration of the loop while continue terminates only the current iteration of the loop.

  • The break statement in C programming is used in the control statements to alter the flow of the execution. The syntax of the break statement is as follows: break; that is the keyword “break” followed by a semicolon.

  • The continue statement in C programming is used in the control statements to alter the flow of the execution. The syntax of the continue statement is as follows: continue; that is the keyword “continue” followed by a semicolon.

Follow us for latest updates