Help the world stop coronavirus! Stay home!

Prev Next

Java / Control Statements

Does returning a value from the loop body break the loop?

Yes. return statement breaks the loop and returns from the entire method immediately. The only code that will be executed is the finally clause and the release of any synchronized statement.

public class ForLoopReturnExample {

public static void main(String[] args) {

	for (int i = 0; i < 10; i++) {
		try {
			if (i == 1)
			System.out.println(" try block. i = " + i);
		} finally {
			System.out.println(" finally block i=." + i);

The same applies to the break statement as well, the finally clause will be executed before exiting the loop.

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

Access Modifiers

Comments & Discussions