this post was submitted on 30 Sep 2023
914 points (96.3% liked)
Programmer Humor
32203 readers
487 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
One of these days I'll read through the PEP and figure out why Python doesn't have do-while. I understand that it's just as bad, but while(True) feels so dangerous.
Curious what use case you have for needing a do-while. Honestly I barely use while at all, a good ol for-loop normally does the trick
The use cases definitely do come up where you want the logic inside the loop to execute at least once. One common use case I have is validating user input in console applications. Put the instructions for validating the user's inputs inside a do while and then run logic to validate it at the end - that way you can easily loop back to the start and re-prompt them for the user input again.