当前位置:网站首页>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。
边栏推荐
猜你喜欢
随机推荐
C language tutorial (1) - preparation
MySql to create data tables
代码执行漏洞
永恒之蓝漏洞复现
什么是EVM兼容链?
Eternal blue bug reappears
gin框架学习-Casbin进阶之策略管理API使用方法
小白学爬虫——爬虫入门
变量的解构赋值
利用phpstudy搭建DVWA
About integrating superset into your own project
Using IIS10 to build an asp website in win11
10 【高度塌陷与BFC】
[swagger close] The production environment closes the swagger method
SQL注入中数据库的判断
npm WARN config global `--global`, `--local` are deprecated. Use `--location解决方案
leetcode-每日一题1252. 奇数值单元格的数目(模拟优化)
Take you to understand the MySQL isolation level, what happens when two transactions operate on the same row of data at the same time?
leetcode-每日一题745. 前缀和后缀搜索(哈希和字典树)
Several solutions for mysql startup error The server quit without updating PID file