Practice mode Python

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

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

Links and website addresses are not allowed in comments.