第二十讲—— Break 与continue
第二十讲—— Break 与continue
break
break用于强制退出循环,但是不会停止程序
package scanner;
public class Demo05 {
public static void main(String[]args){
int i = 0;
while(i<10){
i++;
System.out.println(i);
if(i==5){
break;
}
}
System.out.println("Hello World!!!");
}
}
显示
C:\Users\夏天的风\Desktop\DEMO-XXZ\out\production\DEMO-XXZ scanner.Demo05
1
2
3
4
5
Hello World!!!
Process finished with exit code 0
continue
continue用于循环语句中,用于终止某次循环过程,从头开始
package scanner;
public class Demo05 {
public static void main(String[]ages){
int i = 0;
while(i<10){
i++;
System.out.println(i);
if(i==5){
continue;
}
}
System.out.println("Hello World!!!");
}
}
显示
C:\Users\夏天的风\Desktop\DEMO-XXZ\out\production\DEMO-XXZ scanner.Demo05
1
2
3
4
5
6
7
8
9
10
Hello World!!!
Process finished with exit code 0
新增单词
| 1 | continue | 循环回到开头 | 继续(不确定什么意思待,,,) | 肯谭妞~ | |
|---|---|---|---|---|
| 2 | break | 跳出while|打破 | 布雷克~ |
如果你有梦想 就努力去实现 就这样

浙公网安备 33010602011771号