Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Thursday 18 July 2013

Differences between 'break' and 'continue' statements

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; }

 3. break can be used with for, while, do- while, and switch statements. When break is used in nested loops          i.e. within the inner most loop then only the innermost loop is terminated.
 3. 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.

 4. Example: i = 1, j = 0; while(i<=5) { i=i+1; if(i== 2)break; j=j+1; }
 4. Example: i = 1, j = 0; while(i<=5) { i=i+1; if(i== 2)  continue; j=j+1; }

No comments:

Post a Comment