breakandcontinue.java
来自「Java编程思想第三版,作者书中全部原代码,」· Java 代码 · 共 41 行
JAVA
41 行
//: c03:BreakAndContinue.java
// Demonstrates break and continue keywords.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import com.bruceeckel.simpletest.*;
public class BreakAndContinue {
static Test monitor = new Test();
public static void main(String[] args) {
for(int i = 0; i < 100; i++) {
if(i == 74) break; // Out of for loop
if(i % 9 != 0) continue; // Next iteration
System.out.println(i);
}
int i = 0;
// An "infinite loop":
while(true) {
i++;
int j = i * 27;
if(j == 1269) break; // Out of loop
if(i % 10 != 0) continue; // Top of loop
System.out.println(i);
}
monitor.expect(new String[] {
"0",
"9",
"18",
"27",
"36",
"45",
"54",
"63",
"72",
"10",
"20",
"30",
"40"
});
}
} ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?