当前位置:网站首页>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。
边栏推荐
- Getting to know regular expressions
- leetcode-每日一题1252. 奇数值单元格的数目(模拟优化)
- 初识正则表达式
- npm WARN config global `--global`, `--local` are deprecated. Use `--location solution
- leetcode-每日一题731. 我的日程安排表 II
- Detailed explanation of pointers in C language
- MySql创建数据表
- Artifact SSMwar exploded Error deploying artifact.See server log for details
- MySQL压缩包方式安装,傻瓜式教学
- MySQL分页查询的5种方法
猜你喜欢
![[uiautomation] Get WeChat friend list (stored in txt)](/img/26/1f3424c5998c52c6e10ced8529012a.png)
[uiautomation] Get WeChat friend list (stored in txt)

闭包(五)----一个常见的循环

Using IIS10 to build an asp website in win11

leetcode-每日一题剑指 Offer II 041. 滑动窗口的平均值(队列模拟)

mysql password modification method in Linux (pro-test available)

Digital twins will be an important way to enter the "metaverse"

Yuan prospect and four track of the universe

Access database query

元宇宙的前景及四大赛道

Linux modify MySQL database password
随机推荐
MySQL高级SQL语句(二)
On the side of Ali, tell me what are the application scenarios of message middleware you know?
leetcode-每日一题735. 行星碰撞(栈模拟)
leetcode-每日一题1252. 奇数值单元格的数目(模拟优化)
动态规划(一)| 斐波那契数列和归递
The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
常见JVM面试题及答案整理
代码执行漏洞
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]
一文速学-玩转MySQL获取时间、格式转换各类操作方法详解
永恒之蓝漏洞复现
mac10.14中安装mysqldb
闭包(五)----一个常见的循环
MySQL面试题大全(陆续更新)
了解SSRF,这一篇就足够了
碎片化NFT(Fractional NFT)
The latest MySql installation teaching, very detailed
【uiautomation】微信好友列表获取(存储到txt中)
Volatility取证工具使用日记
About integrating superset into your own project