Files
javaSE251223/day03/src/com/inmind/Demo07_break.java

26 lines
666 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind;
/*
循环的控制_break
break有2个作用
1.结束switch语句
2.结束循环
*/
public class Demo07_break {
public static void main(String[] args) {
/*int i = 10;
if (i == 10) {
break; 错误switch或循环之外无法使用break
}*/
//需求跑10圈但是在跑到第5圈的时候身体不适就停止跑步
for (int i = 1; i < 11; i++) {
if (i == 5) {
//跑到第5圈的时候,提前结束整个循环
break;
}
System.out.println(i);
}
System.out.println("程序结束");
}
}