day03-循环的控制-break关键字
This commit is contained in:
27
day03/src/com/inmind/control06/BreakDemo12.java
Normal file
27
day03/src/com/inmind/control06/BreakDemo12.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package com.inmind.control06;
|
||||||
|
/*
|
||||||
|
循环控制_break
|
||||||
|
break的作用:
|
||||||
|
中断循环
|
||||||
|
中断switch
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class BreakDemo12 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int i = 10;
|
||||||
|
/*if (i > 5) {
|
||||||
|
break; 注意:在switch和loop循环中使用
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//跑10圈,跑到第5圈,跑不动了,不跑了
|
||||||
|
for (int j = 1; j <= 10; j++) {
|
||||||
|
System.out.println("跑了第"+j+"圈");
|
||||||
|
//判断下是否是第5圈,如果是,提前终止
|
||||||
|
if (j == 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("程序结束");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user