当前位置:网站首页>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。
边栏推荐
猜你喜欢
【ubuntu20.04安装MySQL以及MySQL-workbench可视化工具】
[Cloud native] Ribbon is no longer used at the bottom layer of OpenFeign starting from the 2020.0.X version
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
[JVM Loading]---Class Loading Mechanism
leetcode-每日一题558. 四叉树交集(分治递归)
MySQL高级语句(一)
闭包(三)----执行环境
Eternal blue bug reappears
Yuan prospect and four track of the universe
动态规划(一)| 斐波那契数列和归递
随机推荐
闭包(二)
小白学爬虫——爬虫入门
Memcached :安装
08 【生命周期 组件】
Build DVWA with phpstudy
工件SSMwar exploded 部署工件时出错。请参阅服务器日志了解详细信息
Redis:安装使用
年终总结——岁月静好~
MySQL-如何分库分表?一看就懂
MySQL压缩包方式安装,傻瓜式教学
Install mysqldb in mac10.14
leetcode-每日一题745. 前缀和后缀搜索(哈希和字典树)
【ubuntu20.04安装MySQL以及MySQL-workbench可视化工具】
Xiaobai learns reptiles - introduction to reptiles
Access database query
leetcode-438. 找到字符串中所有字母异位词(滑动窗口)
mysql password modification method in Linux (pro-test available)
安装Multisim出现 No software will be installed or removed解决方法
[swagger close] The production environment closes the swagger method
gin框架学习-Casbin入门指南(ACL、RBAC、域内RBAC模型)