当前位置:网站首页>js中的break与continue退出
js中的break与continue退出
2022-07-31 05:11:00 【杂乱无章的我】
break与continue语句对循环中的代码进行了更强力的控制。
break与continue语句的不同区别:
break 语句可以立即退出循环,阻止再次反复执行任何代码。
而 continue 语句只是退出当前循环,根据控制表达式还允许继续进行下一次循环。
break退出:
break关键字可以用来退出switch或循环语句,不能在if语句中使用break与continue。
break关键字,会立即停止离它最近的那个循环语句。
continue退出:
continue关键字可以用来跳过当次循环,同样continue也是默认会对离它最近的循环起作用。
continue关键字会用来跳过当次循环。
break退出:
break退出:
for(var i=0; i<5; i++){
console.log(i);
if(i == 2){
break;
}
}
输出结果为0;1;2。
continue退出:
continue退出:
for(var i=0; i<5; i++){
if(i==2){
continue;
}
console.log(i);
}
输出结果为0;1;3;4。
边栏推荐
- MySQL compressed package installation, fool teaching
- The latest MySql installation teaching, very detailed
- Understanding SSRF, this article is enough
- leetcode-每日一题558. 四叉树交集(分治递归)
- 【JVM加载】---类加载机制
- 12 【网页布局总结 元素的显示与隐藏】
- 动态规划(一)| 斐波那契数列和归递
- MySql to create data tables
- 碎片化NFT(Fractional NFT)
- Common JVM interview questions and answers
猜你喜欢
什么是 GameFi?
04 【计算属性 侦听属性】
DeFi Token in the project management
数字孪生将成为进入“元宇宙”一项重要的途径
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]
The server time zone value ‘й‘ is unrecognized or represents more than one time zone
【Elastic-Job源码分析】——作业监听器
Redis:安装使用
What is GameFi?
[Elastic-Job source code analysis] - job listener
随机推荐
feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
What is an EVM Compatible Chain?
"limit" query in Oracle database
PHP中abstract(抽象)、final(最终)和static(静态)原理与用法
闭包(四)----IIFE
Memcached :安装
局部变量成员变量、引用类型、this,static(第五天)
Xiaobai learns reptiles - introduction to reptiles
安装Multisim出现 No software will be installed or removed解决方法
Common JVM interview questions and answers
11 【定位】
[Cloud native] Open source data analysis SPL easily copes with T+0
5 methods of MySQL paging query
【Elastic-Job源码分析】——作业监听器
小白学爬虫——爬虫入门
Detailed explanation of pointers in C language
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
Using IIS10 to build an asp website in win11
Linux中mysql密码修改方法(亲测可用)