?? Day5 of #100DaysOfPython ??
Surya Singh
Sr. AI/ML Consultant & Team Lead @Accenture Strategy | ex-ZS, EY | MS in ML & AI
Today, we're diving into using else in for loops!
How does an else function when used with for loops?
else is executed at the end of the for loop when the loop has finished running. However, this only happens in case the loop terminates on it own after running all iterations and is not terminated using break
What happens when the for loop is terminated using break?
Let's see in the code snippet below!
In this case the body of else is not executed as the loop is terminated using break.
What other examples can you think of using else with loops?