Use of else block with Python loops
An awesome feature that most programming languages do not offer
Published in
3 min readMay 16, 2020
--
“An
else
block can exist only when anif
block exists before it.”
As a programmer not belonging to Python background, I was a strict follower of this rule. But I was left awestruck and confused after I saw one of my friends’ Python code that used an else
block after a for
loop. So, I performed some research and found that Python provides a feature, that allows us to use an else
block with for
and while
loops. The else
block after a for
or…