Recall & Review
beginner
What happens when a
return statement is executed inside a loop in Java?The method immediately stops executing and returns the specified value. The loop and the rest of the method do not continue.
Click to reveal answer
beginner
Can a
return statement inside a loop be used to exit the method early?Yes, using
return inside a loop lets you stop the method as soon as a condition is met, without finishing the entire loop.Click to reveal answer
beginner
Consider this code snippet:<br>
for (int i = 0; i < 5; i++) {
if (i == 2) return i;
}<br>What will this method return?It will return 2 as soon as
i equals 2, exiting the loop and the method immediately.Click to reveal answer
beginner
Is it possible for code after a loop to run if there is a
return inside the loop?No, if the
return inside the loop is executed, the method ends immediately and code after the loop does not run.Click to reveal answer
intermediate
Why might you use a
return inside a loop instead of a break?Using
return stops the whole method and returns a value, while break only stops the loop but continues the method.Click to reveal answer
What happens when a
return statement inside a loop is executed?✗ Incorrect
A
return inside a loop ends the entire method immediately, returning the specified value.In Java, which statement stops only the loop but continues the method?
✗ Incorrect
break stops the loop but the method continues after the loop.If a
return is inside a loop and never executed, what happens?✗ Incorrect
If
return is never reached, the loop runs fully and the method continues after the loop.Which of these is true about
return inside a loop?✗ Incorrect
return exits the entire method immediately, not just the loop.What is the difference between
return and break inside a loop?✗ Incorrect
return stops the whole method, while break stops only the loop.Explain what happens when a
return statement is used inside a loop in Java.Think about how <code>return</code> affects method flow.
You got /4 concepts.
Describe the difference between using
return and break inside a loop.Consider what happens to the method after each statement.
You got /4 concepts.