How can you prematurely exit a loop in Java?

  • break statement
  • continue statement
  • goto statement (not recommended)
  • return statement
You can use the break statement to prematurely exit a loop in Java. When break is encountered within a loop, it immediately terminates the loop's execution, allowing you to exit the loop based on a certain condition or event. It is a commonly used control flow statement for loop termination.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *