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:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] AMillionMonkeys@lemmy.world 14 points 1 year ago (7 children)

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.

[–] tdawg@lemmy.world 6 points 1 year ago (3 children)

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

[–] MrLuemasG@lemmy.world 4 points 1 year ago

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.

load more comments (2 replies)
load more comments (5 replies)