JScript Language Elements

| Tutorial | Reference |

Controlling Program Flow

| Conditionals | Looping | Break and Continue |

The break and continue Statements:
JScript provides another way of escaping from loops. The break statement can be used to stop execution if some (presumably special) condition is met.

The continue statement jumps immediately to the next iteration, skipping the rest of the command block.

EXAMPLES:
var theRemainder = 0;
var theEscape = 3;
var checkMe = 27;
for (kcount = 1; kcount <= 10; kcount++) 
{
    theRemainder = checkMe % kcount;
    if (theRemainder == theEscape)  
      {
            break;        
      //  Quits from the loop at the first encounter with a remainder that equals the escape.
      }
     document.write(checkMe + " divided by " + kcount + " leaves a remainder of  " + theRemainder + "<br>");
}

for (kcount = 1; kcount <= 10; kcount++) 
{
   theRemainder = checkMe % kcount;
   if (theRemainder != theEscape)  
   {
      continue;        
   // Selects only those remainders that equal the escape, ignoring others.
   }
   document.write(checkMe + " divided by " + kcount + " leaves a remainder of  " + theRemainder + "<br>");
}



© 1996 by Microsoft Corporation.