You Can Do WHAT With While Loops?!?

preview_player
Показать описание
You can do what with while loops?!? #python #code #shorts
Рекомендации по теме
Комментарии
Автор

"Python isn't cursed."
*The while else:*

Jarikraider
Автор

"Extra Hidden Functionality" is Python's middle name.

danmartens
Автор

For anybody wondering, this also works with for loops

tuhilsd.i.yscience
Автор

If anyone wonders why it's called "else", that's because any loop is under the hood if+go to statements. I recommend watching mCoding video on the subject

LauPaSat-pl
Автор

I know of this for 20 years, and coded in Python for 20 years, and there was not a single time i used this feature. Simply in practice it never is what you actually want to do, plus it introduces extra indentation level.

movaxh
Автор

Use this if you want other people to be confused with the code flow.
Just because the syntax exists doesn't mean you should use it as it is likely to cause bugs because people are not aware of this.

rockstardonut
Автор

You can just print success or any other stuff after the while loop has ended without writing else clause. It looks cool but it’s useless. No?

karanveersingh
Автор

i didn't know this and this solves most of my loop based problems

codeiscool
Автор

It doesn’t make grammatical sense at all, this feels like a bug that was implemented as a “feature”

tocraft
Автор

I've been using Python since 1996 and while (groan) I have always known this has existed, I have still yet to find a use case for it.

vorpal
Автор

I've been coding in python for almost 10 years and I learn something new from this channel every day. Kudos!

Landonismo
Автор

I have always thought of it as “if it doesn’t break, then something went wrong, so go into the else…”

JordanMetroidManiac
Автор

"extra hidden functionality" that's right there in the docs

DoolanDrum
Автор

This will be perfect for writing esoteric code

zee-anime
Автор

So if it fails, it's a success. Got it!

humanrightsadvocate
Автор

I don't understand why everyone is hating on else being used in a while loop, it seems pretty useful. Like in this example the condition is no longer met, and it tells you that. I can imagine instances where knowing the condition is no longer satisfied could be useful.

TheBomb
Автор

This is a prime example of what I don't like about formatted languages - like python. If you look at the code, what do you see. While and else together on the same level. WTF is the first thing that comes to mind. Instead of devoting all your attention to the nature and purpose of the code, you have to take the time to understand its syntax.

Andris_Briedis
Автор

Its works for "FOR" loop too 💀

major
Автор

I would expressly test if i>2
Also continue would take away some of the goto worries...
Presumably whiles using list comprehension can also have these else: statements

simonmasters
Автор

I think while then would sound more natural

shiinondogewalker