当前位置:网站首页>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
边栏推荐
- B. Eastern Exhibition- Codeforces Round #703 (Div. 2)
- OSPF comprehensive experimental configuration
- 322. Change
- Open source quantum development framework cirq
- Go IO operation - file write
- [MySQL learning] install and use multiple versions of MySQL, MySQL 8 and MySQL 5.7 at the same time, compressed version
- TCP connection principle
- 拉格朗日插值法
- Connected graph (day 72)
- Go IO operation - file read
猜你喜欢

The error of van swipe in the rotation chart: cannot read a properties of null (reading width)

openEuler 资源利用率提升之道 01:概论

Super complete PMP reference document summary

Tweenmax+svg Pikachu transformation ball

Hcip --- BGP comprehensive experiment

Huawei then responded to the rumor of "cleaning up employees over the age of 34". How can programmers cope with the "35 year old crisis"?

MySQL sub database and sub table and its smooth expansion scheme

Babylon.js cool canvas background animation JS special effects
![[MySQL learning] install and use multiple versions of MySQL, MySQL 8 and MySQL 5.7 at the same time, compressed version](/img/08/3765b34809cc4c723608f5d2e86ed4.png)
[MySQL learning] install and use multiple versions of MySQL, MySQL 8 and MySQL 5.7 at the same time, compressed version

什么是IMU?
随机推荐
CMT registration - Google Scholar ID, semantic scholar ID, and DBLP ID
JVM initial
Ugui source code analysis - Mask
LeetCode-栈和队列刷题
summernote 字体显示中文
Huawei then responded to the rumor of "cleaning up employees over the age of 34". How can programmers cope with the "35 year old crisis"?
JVM初始
CMT 注册——Google Scholar Id,Semantic Scholar Id,和 DBLP Id
JS small game running bear and cat source code
All codes of selenium
About Aries framework addition, deletion, modification and query - query demo
Xiaodi and Xiaohui
The simple use of ADB command combined with monkey is super detailed
轮播图van-swipe的报错:cannot read a properties of null(reading width)
Ugui source code analysis - imaskable
Customize the default width and height of kindeditor rich text
Simulink code generation: variable subsystem and its code
Unity 消息推送
summernote富文本编辑器
[hdlbits questions] Verilog language (2) vectors