class BreakLoop {
public static void main(String args[]) {
for(int i=0; i<100; i++) {
if(i == 10) break;
System.out.println("i: " + i);
}
System.out.println("Loop complete.");
}
}
class Continue {
public static void main(String args[]) {
for(int i=0; i<10; i++) {
System.out.print(i + " ");
if (i%2 == 0)
continue;
System.out.println("");
}
}
}
class Return {
public static void main(String args[]) {
boolean t = true;
System.out.println("Before the return.");
if(t) return;
System.out.println("This won't execute.");
}
}
沒有留言:
張貼留言