Else Clauses on Loops

Else Clauses on Loops

Did you know that loop statements may have an else clause?
Well, it turns out that they can be used!

  • else clause will be executed when the loop completes all of the iterations with for loop and when the condition becomes false with the while loop.

Example:

Output:

Searching...  
Searching...  
Searching...  
Searching...  
Searching...  
Searching...  
Searching...  
Searching...  
Treasure not found :(
  • But else clause will not be executed when a break statement terminates the loop.

Example:

Output:

Searching...  
Searching...  
Searching...  
Searching...  
Found the treasure

Who Am I?

I’m Aswin Barath, a Software Engineering Nerd who loves building Web Applications, now sharing my knowledge through Blogging during the busy time of my freelancing work life. Here’s the link to all of my craziness categorized by platforms under one place: https://linktr.ee/AswinBarath

Join me to learn Python!

Checkout my Python Programming Series where my mission is to share my knowledge on Python: aswinbarath.hashnode.dev/series/python-prog..

Learn what I know about Python from any of my favourite knowledge sources:

Keep Learning

Now, I guess this is where I say GoodBye👋.
But, hey it’s time for you to start learning with your newfound Knowledge(Power)👨‍💻👩‍💻 .
Good Job that you made it this far 👏👏
Thank you so much for reading my Blog🙂.