JavaScript Editor Ajax toolkit     Ajax website 



Main Page

The break statement in JScript stops the execution of a loop if some condition is met. (Note that break is also used to exit a switch block). The continue statement can be used to jump immediately to the next iteration, skipping the rest of the code block while updating the counter variable if the loop is a for or for...in loop.

Using break and continue Statements

The following example illustrates the use of the break and continue statements to control a loop.

В CopyCode imageCopy Code
for(var i = 0;i <=10 ;i++) {
   if (i > 7) {
      print("i is greater than 7.");
      break; // Break out of the for loop.
   }
   else {
      print("i = " + i);
      continue; // Start the next iteration of the loop.
      print("This never gets printed.");
   }
}

The output of this program is

В CopyCode imageCopy Code
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i is greater than 7.

See Also



JavaScript Editor Ajax toolkit     Ajax website


©