{Break VS Continue} : Difference between Break and Continue in C


Let’s consider one of the most confusing topics among all that is loop control statements break and continue in c language let’s get started…

Generally this both statement looks like very opposite but there is just a little bit difference between break and continue in c language so let's understand both the topic with example.   

 

Break statement in c

The break statement is used to terminate from the loop, suppose any loop contains break statement then if then that program executes and break comes into the picture and execute then compiler comes out of the loop no matter what is written after that the rest of the statement which is written after that will not get evaluated.

Let’s understand break statement with one example here I write one program in this program you need to enter one number and here break statement only occurs when you enter negative number so come let’s see...

 

 

So this is the code you can see here break statement occurs only when you enter negative number let’s see the output below.

 

Continue statement in c

Continue statement is similar to break statement, it instead of terminating from the loop it forces to execute the next iteration of the loop.

Let’s understand with one more example. Write a program to print all odd numbers from 1 to 20.

Here I am giving you two type of example one is with continue statement and second is without continue statement let’s starts with continue statement along with output.

 


The output of the code using the break statement.

 

Let’s see the code without continue statement below:

 


The output of the code

 


Here I present you both the code with and without continue statement you can see a clear difference between both although I am explaining the Here brief difference between break and continue statement in c so let’s see...

 

Difference between break and continue in c :

 

Break

continue

The break statement is used to terminate the loop.

Continue statement is used to continue the next iteration of the loop.

It us used in loop and switch case.

It only used in the loop.

The keyword ‘Break’ is used to used in break statement.

The keyword ‘continue’ is used in continue statement.

Control is transfer outside the loop.

Control remains in the same loop.

  

 

Comments

Popular posts from this blog

HR full form - HR Work in company | Full Guide

Compilers vs Interpreters : Difference Between Compilers and Interpreters