Break 和 Continue 的区别

在 C、C++、Java、JavaScript 中都有 Break 和 Coninue,它们使用方法相同。

1、break 命令可以终止循环的运行,然后继续执行循环之后的代码(如果循环之后有代码的话)。

var i=0

for (i=0;i<=5;i++){

  if (i==3){ break }

  document.write("The number is " + i)

  document.write("<br />")

}

The number is 0

The number is 1

The number is 2

2、continue 命令会终止当前的循环,然后从下一个值继续运行。

var i=0

for (i=0;i<=5;i++){

  if (i==3){ continue }

  document.write("The number is " + i)

  document.write("<br />")

}

The number is 0

The number is 1

The number is 2

The number is 4

The number is 5

参考:http://www.w3school.com.cn/js/js_break.asp

原文地址:https://www.cnblogs.com/orientsun/p/2753260.html