Break and Continue Statement in C with Example

Break and Continue statements in C are looping control statements. Based on the break and continue statement loop can be broken or skipped

break and continue both are keywords.

break – Uses to break the loop and also use with a switch to break the switch case.

continue– skip the current execution of the loop and transfer control to the beginning of the loop

For Loop in C programming
While Statement in C Programming
Do While Statement in C Programming

Break Statement in C

To terminate or end the current loop execution break statement is used.

Example of Break Statement in For Loop

Inside for loop, we set some conditions inside the if statement if the condition is true then the break statement executes and transfers control to the outside loop.

Output

Example of Break Statement in While Loop

In the above program, the loop is executed 10 times but inside the loop, if the statement is checking the condition if the value of I equals 5 then breaks the loop.

One statement is out side the loop that is executed after the termination of the loop.

Example of Break Statement in do While Loop

Example of Break Statement in Switch Statement

To terminate switch break statement break is used inside switch case statement

Switch Case in C

Example of Break Statement in Nested Loop

Here break keyword is used inside two loops to check whether two array element matches or not.

if element found then break is used to break inner loop.

Example of Break Statement In User Control Loop

In this program array name is two dimensional array that stores names.

We get input from user and store in name array.

if array is full or user type Bye then we call break statement to end the loop.

Finally we display all names.

This way an infinite loop can be controlled by user.

Continue Statement in C

Continue is used to skip the current loop execution and transfer control to beginning of loop.

Example of Continue Statement in C For Loop

loop will start from 1 and end when it is greater than or equals to 6.

inside loop a condition is checking that i==3 if true then continue is statement is get executed which transfers the control to beginning of loop.

Example of Continue Statement in While Loop

Example of Continue Statement in Do While Loop

What is the use of continue statement in C

Continue is used to skip the current loop iteration and transfer the control to beginning of loop.

What is the use of break statement in C

Break is used to break a inner most loop.

break vs continue in C

break is used to terminate the loop where as continue is used to skip current iteration of loop.

here when i=5 then loop will be terminated

when i=5 then the loop will not continue the current iteration. It will start with other iteration

Here we discussed Break and Continue Statement in C. Hope you all understand