当前位置:网站首页>Jump statements break and continue
Jump statements break and continue
2022-07-24 03:16:00 【Start】
break keyword
break It is mainly used in loop statements or switch In the sentence , Used to jump out of the whole statement block .
break Jump out of the innermost loop , And continue to execute the following statement of the loop .
grammar
break Is very simple to use , It's a statement in a loop structure
break;
Look at a case :
/*
* break:
* Action scenario :switch Select structure and cycle structure
* effect :
* stay switch Encountered in the selection structure break, End the whole switch Selection structure , perform switch Select behind structure
Code for
* Encountered in the loop structure break, Then all subsequent operations of the whole cycle structure are ended , Execute the code after the loop structure
* Be careful :
* break General combination if Select statements to use together
*
*
*/
public static void main(String[] args) {
// 1~10 Add integers between , The cumulative value is greater than 20 The current number of
int sum =0;
for(int j=1;j<=10;j++){
sum+=j;
System.out.println("sum="+sum);
System.out.println("j="+j);
if(sum>20){
break;
}
}Running results
break Use in double loop , In the inner loop break The end is the inner loop , If you want to end the outer loop , You need to use tags to end which loop the table name
public static void main(String[] args) {
//a: b: Marking loops
a:for (int i = 1; i <= 5; i++) {
System.out.print(i + "--");
b:for (int j = 10; j <= 50; j += 10) {
System.out.print(j + " ");
if(j==30){
break a;// Terminate the entire outer cycle
}
}
System.out.println();
}Running results :
continue keyword
continue It can be used in any cycle control structure . The function is to make the program jump to the next iteration of the loop immediately .
stay for In circulation ,continue Statement causes the program to jump to the update statement immediately .
stay while perhaps do…while In circulation , The program immediately jumps to the judgment statement of Boolean expression .
grammar
continue Is a simple statement in the loop body :
continue;
See the sample :
/*
* continue:
* Action scenario :
* It can only act in the circular structure
* effect :
* End the present ( This time ) Cycle subsequent operations , Continue with the next cycle
* Be careful :
* continue General combination if Statement together
*
*
*/
public static void main(String[] args) {
// Output 1-100 Even values between
for(int i =1;i<=100;i++){
// Yes even number allowed output
if(i%2==0){
System.out.println("i="+i);
}
// Otherwise, from the beginning
else{
continue;
}
}
continue It can also be used in double circulation , In the inner loop continue The end is the inner loop , If you want to end the outer loop , You need to use tags to end which loop the table name
边栏推荐
- Summernote supports custom video upload function
- TCP data transmission and performance
- Some properties of differential array operation
- Hcip day 9 notes (OSPF routing feedback, routing policy, and Configuration Guide)
- Ugui source code analysis - maskutilities
- The function of SIP account - tell you what is SIP line
- 水题: 接雨水
- String.split()最详细源码解读及注意事项
- 如何在 pyqt 中实现桌面歌词
- Babylon.js cool canvas background animation JS special effects
猜你喜欢

微信公众号在线客服接入发方法和功能详解

Detailed explanation of wechat official account online customer service access methods and functions

TCP data transmission and performance

轮播图van-swipe的报错:cannot read a properties of null(reading width)

The simple use of ADB command combined with monkey is super detailed

How does the small program mall refine the operation of members?

How to realize software function safety

TCP connection principle

Hcip day 10 (initial BGP border gateway protocol)

I developed an app similar to wechat runnable applet with fluent
随机推荐
B. Eastern Exhibition- Codeforces Round #703 (Div. 2)
An introductory example of structure and combinatorial ideas in go language
C dynamic memory management details
Acwing 4499. draw a circle (similar to a triangle)
Insist on accompanying study
数据湖:Apache Hudi简介
uva1467
go errors
JS Array isaarray () Type of
微信公众号在线客服接入发方法和功能详解
拉格朗日插值法
[C language] file operation
正则表达式 \b \B 深入浅出理解单词边界的匹配
Detailed explanation of wechat official account online customer service access methods and functions
About Aries framework addition, deletion, modification and query - query demo
Summernote font displays Chinese
JVM初始
什么是IMU?
TCP connection principle
The former backbone of WPS spent 10 years building new software. Excel users: I switched to WPS for this