Q: How can a for loop be prematurely terminated in Java?
-
A
Using exit()
-
B
Using return
-
C
Using break
-
D
Using continue
C
Answer:
C
Explanation:
In Java, the break statement is used to prematurely terminate a loop. When a break statement is encountered inside a loop, the loop stops executing, and control is passed to the first statement following the loop. The return statement is used to exit a method, while continue skips the current iteration but does not terminate the loop. exit() is used to terminate the program, not a loop.
Related Topic:
Share Above MCQ