When does the else block of a Python while loop execute?
Correct answer D. When the loop condition becomes false without a break being executed
Explanation
A loop else clause runs when the loop terminates normally, which for while means its condition became false. If break ends the loop early, the else block is skipped. A common use is search loops: else handles the "not found" case without needing a flag variable.
Answer checked How we write and check questions
Discussion