Single Choice
Easy
Q_______ statement is used to exit the current loop.
ID: #22415
Nested Loops in Java Language
159 views
Question Info
#22415Q ID
EasyDifficulty
Nested Loops in Java Language Topic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
The break statement is used to exit the current loop.
Here is an example in Java to demonstrate its usage:
public class BreakStatementExample { public static void main(String[] args) { // Loop from 1 to 5 for (int i = 1; i <= 5; i++) { if (i == 3) { break; // Exit the loop when i is 3 } System.out.println("Iteration: " + i); } System.out.println("Loop exited."); } }
Output:
Iteration: 1 Iteration: 2 Loop exited.
In this example, the break statement exits the loop when i equals 3, so the loop stops executing and the program continues with the next statement after the loop.
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic