must not return in the for statement

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

must not return in the for statement
Do not return when memoizing in Ruby
[Java] Nowadays, the extended for statement is not exclusively for List, isn't it?
ChatWork4j for using the ChatWork API in Java
Compare the speed of the for statement and the extended for statement.
Implement the star five function using the for statement
Does the escape sequence (\) not work? (for Mac)
Solution for NetBeans 8.2 not working in Java 9 environment
The public key for jenkins-2.249.1-1.1.noarch.rpm is not installed
Java for statement
When the project is not displayed in eclipse
Ebean.update () is not executed in the inherited model.
Remedy for command not found in rails s
Return the execution result of Service class in ServiceResponse class
[For beginners] DI ~ The basics of DI and DI in Spring ~
[Rails] Return login result in JSON format (for beginners)
A note for Initializing Fields in the Java tutorial
I tried using an extended for statement in Java
[Processing] Can Perlin noise return in the opposite direction?
[Error] The app is not displayed in the production environment
In Ruby, methods with? Do not always return true/false.
[Java] for statement, while statement
Complex for statement (basic)
[Java] for statement / extended for statement
"The Language Support for Java server crashed 5 times in the last 3 minutes. The server will not be restarted."
For those who have deleted a document in Firestore but the subcollection does not disappear
(Memo) Java for statement
Ruby Learning # 16 Return Statement
Store in Java 2D map and turn with for statement
[Java] Make variables in extended for statement and for Each statement immutable
I translated [Clone method for Java arrays] as the Clone method in Java arrays.
The story when the test folder was not created in Rails
JSON in Java and Jackson Part 1 Return JSON from the server
The lifecycle method [methodName] must not throw a checked exception.
The case that @Autowired could not be used in JUnit5
Error in production environment (The asset "~" is not present in the asset pipeline.)
Create a method to return the tax rate in Java
The idea of C # (lambda expression, for statement) to chew
Line breaks in the entered text are not displayed in view
If the submodule assets are not found in the Play Framework
[Development log ⑬] Do not let 0 be entered in the form !!
I want to return multiple return values for the input argument
Check if Ethereum transactions are not included in the block
I want to simplify the conditional if-else statement in Java
In order not to confuse the understanding of getters and setters, [Do not use accessors for anything! ]