hamburger

Difference Between Break and Continue Statements in C

By BYJU'S Exam Prep

Updated on: September 25th, 2023

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

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

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 OOP Difference Between List and Tuple in Python
Difference Between Unique and primary key Difference Between Calloc () and Malloc ()
Difference Between Mealy machine and Moore machine Difference Between High-Level and Low-Level Languages
Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium