{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. 

so let's start

What is the difference between break and continue Statement explain 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.

  

As you know in this post we covers some questions like
 

1. What is the role of break and continue statements?

Ans: as you know continue and break statements used within loops to control flow of program. continue change the flow and execute next statement of the loop to run immediately, at other side break is used to terminates the loop.

 

2. What is the use of continue statement?

Ans: After reading this article you get the idea that The continue statement executes the further iteration of a particular loop.

 

3. What is the use of Break statement?

Ans: Basically in simple words break statement is used to terminate the loop.

 

4. Does Break stop all loops?

Ans: You can see in example that Break statement is used to terminate the loop. 

 

5. How does continue work?

Ans: Continue statement forces the next iteration of the loop to to e execute.

 

6. Does continue statement works without loops?

Ans: As you know we use this statement break and continue in different types of loop like while or do while and many more but it can't execute without the loop.

 

7. Which of this is used to skip one iteration?

Ans: In the Concept of beak and continue you get that Continue is used to skip some amount block of statements and direct executes other steps.

 

8. Can Break be used in if statement?

Ans: No, we can not use break statement in if statement.

Reactions

Post a comment

0 Comments