A developer writes code to iterate over a list and break when a certain condition is met. Which keyword is used to exit the loop prematurely?
The break statement immediately terminates the innermost enclosing loop, transferring control to the first statement after it. This matches the stem's requirement to exit prematurely once a condition is met, unlike continue, which skips only the current iteration.
Why this answer
The `break` keyword is used in Python to immediately exit the nearest enclosing loop (for or while) when a specified condition is met, allowing the program to resume execution at the next statement after the loop. This is the standard mechanism for premature loop termination in Python, as defined in the language specification.
Exam trap
Python Institute often tests the distinction between `break` and `continue`, where candidates mistakenly think `continue` can exit a loop, but it only skips the current iteration and proceeds to the next one.
How to eliminate wrong answers
Option B is wrong because `stop` is not a Python keyword; it has no meaning in loop control and would raise a NameError if used. Option C is wrong because `exit` is a function (typically from the `sys` module) used to terminate the entire program, not just the loop, and is not a keyword for loop control. Option D is wrong because `continue` does not exit the loop; it skips the rest of the current iteration and jumps to the next iteration of the loop.