ProAnswers.org

What is the difference between 'break' and 'continue' statements in C?

Differences between ‘break’ and ‘continue’ statements

break continue

  1. break is a keyword used to terminate the loop or

exit from the block. The control jumps to next

statement after the loop or block.

  1. continue is a keyword used for skipping the current

iteration and go to next iteration of the loop

2.Syntax:

{

Statement 1;

Statement 2;

Statement n;

break;

}

2.Syntax:

{

Statement 1;

continue;

Statement 2;

}

  1. break can be used with for, while, do- while, and switch statements. When break is used in nestedloops i.e. within the inner most loop then only the innermost loop is terminated.

  2. This statement when occurs in a loop does not terminate it but skips the statements after this continue statement. The control goes to the next iteration. Continue can be used with for, while and do-while.

  3. Example:

i = 1, j = 0;

while(i<=5)

{

i=i+1;

if(i== 2)

  1. Example:

i = 1, j = 0;

while(i<=5)

{

i=i+1;

if(i== 2)

break;

j=j+1;

}

continue;

j=j+1;

}