「Java入門」returnの終了処理のサンプル
Javaコード
package sample;
public class EndTestDemo {
public static void testfunc() {
for (int i = 0;; i++) {
System.out.println(“child method");
if (i == 3) {
return;
} else {
System.out.println(+i);
}
}
}
public static void main(String[] args) {
testfunc();
System.out.println(“main method");
}
}
結果
child method
0
child method
1
child method
2
child method
main method