javaScript break   continue   label statement

the javascript break statement terminates the current loop,or if in conjunction with a label, terminates the associated statement.

the javascript continue statement 'jumps over' one iteration in the loop.

javaScript break statement

the break terminates the current loop,or if in conjunction with a label, terminates the associated statement.


         break [ label ] ;
     function    infinite(){
               while( true )
                                document.write("it's infinite loop you can break this");
               }   infinite();

in the below example testbreak() function has a break statement that terminates the for loop when i is 4, and returns the value 4*i.

 function   testbreak(x){
                  for ( var  i = 0; i < 6 ; i++ ){
                                           if ( i == 4 ) break;
                                     return  4*x;

javaScript continue statement

the javascript continue statement is used to stop the current iteration of a loop, and continues program flow with the beginning of the loop.

the javascript continue statement only inside a while, do  . . . while, for or for  . . . in loop.

 function   testcontinue(x){
                  for ( var  ii = 0; ii < 8 ; ii++ ){
                                           if ( ii < 4 ) {continue;}
     document.write("<br/>"+"the value of ii if not  continue the loop____"+ ii);

the break and continue statements can be used to more precisely control the execution of a loop.the break statement, which was briefly introduced with the switch statement, look our switch case chapter,but simply break is used to exit a loop early, breaking out of the enclosing curly braces.

the continue, statement tells the interpreter to immediately start the next iteration of the loop.when it's encountered, program flow will move to the loop check expression immediately.

javaScript label statement

the label statement is used to provides an identifier for a statement.

label statement can be used with break and continue to direct flow control more precisely.

a label is simply an identifier followed by a colon that is applied to a statement or block of code.


         label :  statements 
function  labeloutput(){
   outer: for( var i = 0 ; i < 5 ; i++ ) {
       inner: for( var j = 0 ; j < 5 ; j++ ){
                   if ( i== j ) {
                                  document.write("<br/>"+"the  i == j " + i +"  "+ j);
                                  break inner;
                  if ( i < 3 )  { continue outer; } 
                            else   {
                                    document.write("<br/>"+"the i value___"+ i );