break Statement in C

For Complete YouTube Video: Click Here

In this class, we will try to understand the break Statement in C.

The use of the break statement has already done in the switch statement.

break Statement

We may need a loop with an exit point in the middle or want to have multiple exit points. In that case, we can use a break statement.

The use of break statements can be done in switch statements and loops only.

break Statement Example

The image below is an example program for the use of break statements in the loops.

break Statement in C
break Statement in C example

The above example is a program to find whether the given number is prime or not.

A number is said to prime if it is divisible by one and the number itself.

The for loop used in the program will stop its iteration if the given number is divisible by any other number.

The program execution will come out of the loop if the break statement is executed.

The use of a break statement will help the iteration of the loop to stop.

The if conditions below the loop will decide whether the number is prime or not.

If the value of i is less than n, then the number is NOT prime.

Else the value is prime.