break and continue statement in c

Break and continue statement are the statements which used for the stop the loop or skip the specific step in a loop or condition in C.

You can use break and continue statement in loops like for, while, do-while loop, and if, if-else statement and switch-case in C or other programming language.

Break Statement in C

We often come across situations where we want to jump out of a loop instantly, without waiting to get back to the conditional test. The keyword break allows us to do this. When the break is encountered inside any loop, control automatically passes to the first statement after the loop. A break is usually associated with an if.

We can understand it by the following syntax:-

while (<expression>) 
{
<statement>
<statement>
if (<condition which can only be evaluated here>)
break;
<statement>
<statement>
}
// control jumps down here on the break

Continue Statement in C

In some programming situations, we want to take control to the beginning of the loop, bypassing the statements inside the loop, which have not yet been executed. The keyword continue allows us to do this. When a continue is encountered inside any loop, control automatically passes to the beginning of the loop. A continue is usually associated with an if.

We can understand it by the following syntax:-

// control jumps here on the continue
while (<expression>) 
{
...
if (<condition>)
continue;
...
...
}

Recommended Post: