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


    此文转载自: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 id="demo"></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>
    

     演示效果

  • 相关阅读:
    第七次作业
    随堂讨论8
    第六次作业
    随堂讨论-5
    曹宇轩-第五次作业
    随堂讨论3-刘昕昕,曹宇轩
    曹宇轩-第四次作业
    Alpha阶段项目复审
    团队作业4 -项目冲刺
    第六篇 Scrum冲刺博客
  • 原文地址:https://www.cnblogs.com/phyger/p/14036149.html
Copyright © 2020-2023  润新知