The optional “else” in Python loops
shahriar.svbtle.com
The optional “else” in Python loops
1–10 of 50 posts
Re: The optional “else” in Python loops
#2Re: The optional “else” in Python loops
#3While in theory this is useful, it's one of the least intuitive parts of python for me. I avoid them whenever possible because I feel "else" conveys the intent very poorly. (And I've been writing python for years.)
Re: The optional “else” in Python loops
#4While in theory this is useful, it's one of the least intuitive parts of python for me. I avoid them whenever possible because I feel "else" conveys the intent very poorly. (And I've been writing python for years.)
Re: The optional “else” in Python loops
#5While in theory this is useful, it's one of the least intuitive parts of python for me. I avoid them whenever possible because I feel "else" conveys the intent very poorly. (And I've been writing python for years.)
I agree. I use it, but intuitively, I think of else acting the opposite way - if the loop finishes successfully, great! else, do something.
Re: The optional “else” in Python loops
#6While in theory this is useful, it's one of the least intuitive parts of python for me. I avoid them whenever possible because I feel "else" conveys the intent very poorly. (And I've been writing python for years.)
I agree. I use it, but intuitively, I think of else acting the opposite way - if the loop finishes successfully, great! else, do something.
Re: The optional “else” in Python loops
#7While in theory this is useful, it's one of the least intuitive parts of python for me. I avoid them whenever possible because I feel "else" conveys the intent very poorly. (And I've been writing python for years.)
Re: The optional “else” in Python loops
#8Earlier quoted context omitted.
I agree. I use it, but intuitively, I think of else acting the opposite way - if the loop finishes successfully, great! else, do something.
If you're using break to signal success, that is how else acts.
Re: The optional “else” in Python loops
#9While in theory this is useful, it's one of the least intuitive parts of python for me. I avoid them whenever possible because I feel "else" conveys the intent very poorly. (And I've been writing python for years.)
What finally made it intuitive for me: assuming the loop contains an if condition: break, you can consider the else-clause to be the else of the if statement within the loop.
Re: The optional “else” in Python loops
#10While in theory this is useful, it's one of the least intuitive parts of python for me. I avoid them whenever possible because I feel "else" conveys the intent very poorly. (And I've been writing python for years.)