For-else loop in Python 🐍
Mar 17, 2021
In Python, there is an else conditional statement with for/while loop unlike any other programming language, which denotes or executes when for loop is fully completed.
But else statement doesn’t execute in the case for loop terminated in between.
When for loop executes:
In the below case, for loop is executed without break in the loop so the “else” statement also gets executed.
When for loop terminated in between
else statement never executes in case if there is the termination of for-loop
Conclusion- else statement is executed only when for loop does not terminate.