当前位置:网站首页>Day011 循环结构中的跳转语句
Day011 循环结构中的跳转语句
2022-07-22 23:04:00 【陌 年】
break:
作用场景:switch选择结构和循环结构中
作用:
在switch选择结构中遇到break,则结束整个switch选择结构,执行switch选择结构后面的代码
在循环结构中遇到break,则结束整个循环结构后续所有操作,执行循环结构后面的代码
注意:
break一般结合if选择语句一起使用
public class BreakDemo02 {
public static void main(String[] args) {
for (int i = 1; i <=20; i++) {
System.out.println(i);
//判断i的值,看其有没有到10,如果到10了,就应该结束整个for循环
if(i==10){
break;//结束整个for循环
}
}
}
}
continue:
作用场景:
只能作用在循环结构中
作用:
结束当前(本次)循环后续操作,继续执行下一次循环操作
注意:
continue一般结合if语句一起使用
public class ContinueDemo01 {
public static void main(String[] args) {
for (int i = 1; i <= 20; i++) {
if (i == 10) {
continue;// 当i==10时,结束本次循环,进入迭代部分
}
System.out.println(i);
}
}
}
public class BreakDemo01 {
public static void main(String[] args) {
// break在双重循环中的使用,内层循环中的break结束的是内层循环,如果要结束外层循环,需要使用标记来表名结束哪一个循环
// a: b:标记循环
a: for (int i = 1; i <= 5; i++) {
System.out.print(i + "---");
b: for (int j = 10; j <= 50; j += 10) {
if (j == 40) {
continue b;// 终止整个外层循环
}
System.out.print(j + " ");
}
System.out.println();
}
}
}
边栏推荐
- 黑马程序员-接口测试-四天学习接口测试-第二天-接口用例设计,测试点,功能测试,安全测试,性能测试,单接口测试,业务场景测试用例,postman简介,安装
- [arxiv2022] grouptransnet: Group transformer Network for RGB - D Salient Object Detection
- Easily take you to the gate of turtle drawing
- The author believes that the development logic of the meta universe and the Internet is quite different in Chengdu
- When to use usercf and itemcf?
- Go gin: multi file upload
- 笔试强训第21天
- 园区/厂区怎么实现wifi上网短信认证
- Swift - red modifier
- Golang中iota的正确用法
猜你喜欢
随机推荐
云计算或成时代新拐点?从哪些点可以看出?
Algorithm --- 2D array mesh migration (kotlin)
Shell变量、系统预定义变量$HOME、$PWD、$SHELL、$USER、自定义变量、特殊变量$n、$#、$*、[email protected]、$?、env看所有的全局变量值、set看所有变量
又发福利!日历小程序源码
微信小程序中使用全局数据实现数据共享
SSH 免密登陆配置
Promise (I)
DP+回溯分割回文串的系列问题
TensorRT的插件实战(1)
odbc excel--2022-07-21
数的三次方根
Get a control width
Redis事务与锁机制
阿里云国际版账户收到账号风险通知,怎么办?
我们来浅谈代码语言的魅力
Flynk uses liststate to implement keyedstate
This is not a true sense of the meta universe, which should have its own distinctive characteristics and unique development logic
嵌入式系统移植【5】——交叉编译工具链
Redistemplate pipeline use
XMODEM, ymodem and zmodem protocols are the three most commonly used communication protocols








