Jump statements such as return and continue let you change the default flow of program execution, but jump statements
that direct the control flow to the original direction are just a waste of keystrokes.
public void foo() {
while (condition1) {
if (condition2) {
continue; // Noncompliant
} else {
doTheThing();
}
}
return; // Noncompliant; this is a void method
}
public void foo() {
while (condition1) {
if (!condition2) {
doTheThing();
}
}
}
No issue is raised when a return statement inside a try block exits a loop early and a finally block is
executed before leaving the method. Removing the return would let the loop continue after the finally block and change the
behavior.
public void processItems() {
while (item != null) {
try {
if (shouldStop(item)) {
return;
}
} finally {
release(item);
}
item = nextItem();
}
}