If you write return in the for statement, it will only turn once. Of the sample code below for (; ;) Should be an infinite loop, The loop is terminated by return and the process ends immediately.
If you write decent code return needs to be written outside for.
public class ForReturn {
public static void main(String[] args) {
//TODO auto-generated method stub
String result = forReturn(2);
System.out.println(result);
}
public static String forReturn(int i){
for (; ;){
return "failure";
}
}
}
Execution result
failure
It was today that I learned more about that. .. .. .. ..
Recommended Posts