Break and Continue Statement in C with Example

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

break and continue both are keywords.

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

continue– skip the current execution of loop and transfer control to beginning of 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 condition inside if statement if condition is true then break statement executes and transfer control to outside loop.

Output

Example of Break Statement in While 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 loop will not continue current iteration. It will start with other iteration