此文转载自:https://blog.csdn.net/weixin_41937552/article/details/110041295

break 语句用于跳出循环。

continue 用于跳过循环中的一个迭代。

break 语句可用于跳出循环。

break 语句跳出循环后,会继续执行该循环之后的代码(如果有的话):

continue 语句中断循环中的迭代,如果出现了指定的条件,然后继续循环中的下一个迭代。

代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>break及continue</title>
	</head>
	<body>
		<p>测试带有break\continue跳出循环</p>
		<button onclick="myFuntion()">点我测试</button>
		<p ></p>
		<script>
			function myFuntion(){
				var x="";
				for(i=0;i<10;i++){
					if(i==5){
						// break;
						continue;
						
					}
					x=x+"当前的数字为:"+i+"<br/>";
					
				}
				document.getElementById("demo").innerHTML=x;
			}
		</script>
	</body>
</html>

 演示效果

javaScript学习笔记之break 和 continue 语句对比

javaScript学习笔记之break 和 continue 语句对比

相关文章:

  • 2022-01-16
  • 2021-10-29
  • 2021-11-16
  • 2022-12-23
  • 2021-08-04
  • 2021-11-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-05-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
相关资源
相似解决方案