Python Programming - Loops - Discussion

Discussion Forum : Loops - General Questions (Q.No. 3)
3.
What is the purpose of the else block in a Python for or while loop?
It handles exceptions that occur in the loop.
It is executed only if an exception occurs in the loop.
It ensures the code inside the else block always executes, regardless of whether an exception occurs or not.
It is executed when the loop condition becomes False.
Answer: Option
Explanation:
The else block in a loop is executed when the loop condition becomes False, and the loop naturally exits.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.