Break and Continue in C

Break and Continue in C

The break and continue in c statements are used to alter the normal flow of a program. Break and Continue are control statements. While writing programs often time situation occurs where we want to jump out of the loop instantly without waiting to satisfy the conditional test. 

 

Break statement in C

The break statement is used with a conditional if statement. The break is used in terminating the loop immediately after encountered when the break is encountered inside any loop, control automatically passes to the first statement after the loop. The break is used to break the control only from the loop in which it is placed.

 

Syntax

break;

Flowchart of break statement

flowchart of break statement, Break and Continue in C

 

Program of break statement in C

#include <stdio.h>

int main(){

  int i;

  for(i=0; i<10; i++)
  {
      if(i==5)
      {
         
          break;
      }

      printf("%d", i);
  }
   return 0;
}

Output

01234

 

Continue Statement in C

A continue is usually associated with if Statement. It is used for sometimes desirable to skip some statements inside the loop

 

Syntax

continue;

Flowchart of continue statement

 

Flowchart of continue statement and Break and Continue in C

Program of continue statement in C

#include <stdio.h>

int main(){

  int i;

  for(i=0; i<10; i++)
  {
      if(i==5)
      {
         continue;
      }

      printf("%d", i);
  }

   return 0;
}

Output

012346789

 

 

Also, read the Type conversion in C.

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *