From d1e15efe988c91f5a509d3db351422ebf35af3fe Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Thu, 17 Sep 2026 11:37:48 +0800 Subject: [PATCH] =?UTF-8?q?day03--=E5=BE=AA=E7=8E=AF=E7=9A=84=E6=8E=A7?= =?UTF-8?q?=E5=88=B6-break=E5=85=B3=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day03/src/com/inmind/controller05/Demo09.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 day03/src/com/inmind/controller05/Demo09.java diff --git a/day03/src/com/inmind/controller05/Demo09.java b/day03/src/com/inmind/controller05/Demo09.java new file mode 100644 index 0000000..f995e29 --- /dev/null +++ b/day03/src/com/inmind/controller05/Demo09.java @@ -0,0 +1,25 @@ +package com.inmind.controller05; +/* +循环控制_break +break的作用: + 中断循环 + 中断switch + +*/ +public class Demo09 { + public static void main(String[] args) { + /*int a = 4; + if (a == 4) { + break;//错误: break只在 switch 或 loop 内部使用 + }*/ + //跑圈1~10,有个人第4圈开始就不跑了 + for (int i = 1; i < 11; i++) { + //如果是第四圈,就不跑(结束,中断) + if (i == 4) { + break;//中断循环 + } + System.out.println(i); + } + System.out.println("程序结束"); + } +}